jQuery > Selectors

Mutliple selector in jQuery

How to select multiple elements at a time in jQuery?

To select multiple elements having different attributes, multiple selector can be used. We can mix the class selector, element selector, id selector all in this selector separated by “,” (comma). 

<script language="javascript" type="text/javascript">
          $("p.class1, #p1").css("border", "5px solid green");

Above code will

  • select all paragraph (p) having class attribute set as “class1” 
  • and all html elements having id attribute as “p1” 

and apply css style border width as 5 pixel, style as solid and color as green. 

 Views: 1552 | Post Order: 14

Write for us