How to get objects by ID, Class, Tag, and Attribute in jQuery?

Here?s how you can get objects by ID Selector (#id), by Class Selector (.class), by Tag, and Attribute (.attr()).

Get Object by Class Selector

Example

The element class selector selects all the elements which match with the given class of the elements.

   
      jQuery Selector
      
   
      
   
   
   

      
         

This is first division of the DOM.

     
     
         

This is second division of the DOM.

     
   

Get Object by ID Selector

Example

The element ID selector selects a single element with the given id attribute:

   
      jQuery Selector
      
      
   
   
      
         Select a number:
         1          2          3
               
   

Get Object by Tag

Example

For this, pass the name of the specific tag i.e. tag below:

   
      
      
      
   
   
      One
      Two
      

Click any of the link above and you can see the changes.

   

Get Object by Attribute

Example

Using the .attr(), you can get any attribute of any tag. Here?s an example showing how to get an attribute value:


   
      jQuery Example
      

      
   
   
   
      logo
             
Updated on: 2026-03-11T23:14:17+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements