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.


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


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

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

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

#Dec 4 What is Etrieve Flow? #Dec 2 The unique operator($) in Envision Basic #Nov 25 Steps to Install Microsoft SQL Server on a MacOS #Nov 11 What is DevOps? #Nov 10 The * arithmetic operator in Envision Basic #Nov 10 What are Big Data Clusters in SQL Server?
You might also like these
WordPress: How to find all posts from a custom post type with multiple custom fields values?WordPressFull and Partial ROLLUP in Postgresql with ExamplesPostgresModules and its Core features in JavaScriptJavaScriptMySQL queries to get data rows from previous month as well as from last 30 daysSQL/MySQLIN Operator in PostgreSQLPostgresDebugging in WordPress Part 3: SCRIPT_DEBUG and SAVEQUERIESWordPressJavaScript Data Types and Data Structures Things to RememberJavaScriptData Flows in ReactReactWhat is the correct way to enqueue multiple CSS files in WordPress?WordPressHow to convert a number rounding to a specified number of decimals in JavaScript?JavaScriptFile System Integrity: How to Keep an Eye on Your Files and Folder Change?MiscellaneousThe Difference Between isNaN() Method And isNaN() Function In JavaScriptJavaScript