Selector: .class and .class (select element with two/multiple classes)


Here we will see how can we select the elements on our page with two classes. Its syntax is very simple: 
 
$(".class1.class2") 
 
where class1 and class2 are the two classes. The above selector will choose all elements with class="class1" and  
 
class="class2". 
 
Let us take an example : 
 
<!--program starts---> 
<p class='first'>hello</p> 
<p class='second'>how are you</p> 
<p class='first second'>This example shows how to use effects on any object having more than one class. This text will appear  
 
in red color</p> 
 
 
<script type='text/javascript'> 
$(".first.second").css("color","red"); 
 
</script> 
 
 
<!--program ends--> 
 
Copy the above code and try to execute in the jQuery box below, you will see that the third <p> tag text will appear in red  
 
color. Hence the selector $(".first.second") selects the elements with class='first' and class='second'.
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments