Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

W3.JS Selectors


W3.JS Selectors

W3.JS selects HTML elements and perform actions on the selected element(s):

w3.action(selector)
  • The action() is performed on the selected element(s)
  • The (selector) selects the HTML element(s)

Example

w3.hide('p')  // Hide all <p> elements

Try It Yourself » With CSS »

Are you familiar with CSS selectors?

W3.JS uses the CSS syntax to select and manipulate HTML elements.

Selectors are used to "find" (select) HTML elements based on their tag name, id, classes, types, attributes, values of attributes and much more. A list of all selectors can be found in our CSS Selector Reference.


Selector Examples

To select HTML elements, use a tag name:

Hide all <h2> elements:

w3.hide('h2')

Try It Yourself »

To select an element with a specific id, write a hash character, followed by the id of the HTML element:

Hide an element with id="London":

w3.hide('#London')

Try It Yourself »

To select elements with a specific class, write a period character, followed by the name of the class:

Hide all elements with class="city":

w3.hide('.city')

Try It Yourself »


More Selector Examples

Selector Description Example
("*") Selects all elements in the document Try it
(this) Selects the current HTML element Try it
("p.intro") Selects all <p> elements with class="intro" Try it
("div p") Selects all <p> element inside all <div> elements Try it
("div p:first-child") Selects the first <p> element inside all <div> elements Try it
("[href]") Selects all elements with an href attribute Try it
("a[target=_blank]") Selects all <a> elements with a target attribute value equal to "_blank" Try it
("p:nth-child(even)") Selects all even <p> elements Try it

For a complete reference of all CSS selectors, please go to our CSS Selectors Reference.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.