How to select elements by ID using CSS selectors?

To select elements by ID value the # symbol + value synctax can be used.

For example, #product would select any element that contains #product in the id attribute:

<div> <div id="product">select</div> <div id="sold product">select</div> <div id="sold product new">select</div> <div id="product-2">ignore</div> </div>

Note that this selector matches any element that contains the value in the ID list (separated by spaces).
To match elements that contain the exact ID value the predicate syntax can be used:

<div> <div id="product">ignore</div> <div id="sold product">select</div> <div id="sold product new">ignore</div> <div id="product-2">ignore</div> </div>
Question tagged: Css Selectors

Related Posts

Web Scraping With Ruby

Introduction to web scraping with Ruby. How to handle http connections, parse html files for data, best practices, tips and an example project.

Web Scraping With NodeJS and Javascript

In this article we'll take a look at scraping using Javascript through NodeJS. We'll cover common web scraping libraries, frequently encountered challenges and wrap everything up by scraping

Parsing HTML with CSS Selectors

Introduction to using CSS selectors to parse web-scraped content. Best practices, available tools and common challenges by interactive examples.