YogeshChauhan . com

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 */
dreamhost

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 uninstall Cocoapods from the Mac OS? #4 How to add Read More Read Less Button using JavaScript? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

May 5 Use inline if to make a shorter conditional syntax in React May 4 What is Conditional Rendering in React? May 3 How does @extend rule work in SCSS (Sass)? May 2 How different is Handling Events in React vs HTML DOM? May 2 How to create bouncing balls using HTML canvas and JavaScript? Apr 30 HTML canvas methods

You might also like these

How to change value of a span tag using a reference from another div using jQuery?jQueryWhat are Modules and Components in Angular?AngularReading Multiple Inputs in SwiftSwiftFor Each Loop in Swift for BeginnersSwiftHow to Secure Web or Mobile Browsers?MiscLearn to Implement Estimated Reading Time using PHP Part 2: Final Implementation with Source CodePHP4 different ways to create JavaScript ObjectsJavaScriptHow to create a dynamic countdown using HTML and JavaScript?HTMLfirst-of-type and last-of-type selectors in CSSCSSHow to modify the latest post array using get_posts() in WordPress?WordPressEverything you need to know about ANY, SOME and ALL Operators in PostgresPostgresHow to create a simple stopwatch using JavaScript?JavaScript