dots Created with Sketch.
Yogesh Chauhan's Blog

How to select an element using its ID without the high specificity of the ID selector?

in CSS on August 23, 2020

If we use an attribute selector to select an element by its ID then it will have a lower level of specificity than if it was selected with an ID selector. 

For e.g. We can target the same element with [id="ID_name"] and #ID_name but with lower specificity.

HTML


<div id="ID_name">...</div> 

CSS


#ID_name { ... } /* High specificity */

[id="ID_name"] { ... } /* Low specificity */
amazon

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Jul 22 Is there a CSS parent selector? #Jul 22 Difference between :where and :is in CSS #Jul 22 Does :is() pseudo selector hint at CSS preprocessing in the future? #Jul 22 Control Scrolling with CSS Scroll Snap #Jul 21 Control rendering using CSS content-visibility property #Jul 21 How to use @supports rule in CSS?
You might also like these
SQL Inner JoinSQL/MySQLHow to change style of all direct children of an element using jQuery?jQueryFew more :nth-child examples in CSSCSSaddcslashes() and addslashes() String Functions in PHPPHPHow to vertically and horizontally align text and image block (without flex or grid) in CSS?CSSHow to Check If a Variable is an Integer, a Float, a Number, NaN, an Infinite or a Numeric in PHP?PHPHow to add multiple components in React app?ReactHow does Binding work in JavaScript?JavaScriptIs there a CSS parent selector?CSSReading Multiple Inputs in SwiftSwiftHow to create a smooth scrolling effect with CSS?CSSLearn to Make a Simple Contact Us Form using PHP and PDO-MySQLPHP