13
Aug
2012

How to select multiple elements in jQuery

Posted in: jQuery No Comments

jquery_logo
Many times we need to select multiple elements in jQuery. This can be done using comma.

In below code we are going to select two class classone and classtwo.

<script type="text/javascript">
$(document).ready(function() {
$(".classone, .classtwo")
});
</script>

For example, we want to select two class classone and classtwo. On hover background color will change to black and font color will change to white.

<script type="text/javascript">
$(document).ready(function() {
$(".classone, .classtwo").hover(function() {
$(this).css({'background': '#000', 'color': '#fff'});
},
function() {
$(this).css({'background': '#fff', 'color': '#000'});
}
);
});
</script>

Done!!!
Check live demo

About the Author

Name: Ravi Shekhar
I love learning and sharing web stuffs.

Share this post

Twitter Facebook Google Buzz Digg StumbleUpon Delicious Technorati

Leave a Reply