Wednesday, February 29, 2012

How to select different tag elements with jquery?

Consider a page width many tags and you want to select diferent tag.
Make them to a list item and change their css or style.

you can use add() selector.
Consider a page with 5 i tags and 5 b tag.How can I select these tags as a list item?

$("i").add("b");

It's so easy to use with jquery.

DEMO

Hello World! Hello Sun! Hello Moon! Hello Star! Hello Jquery! Hi World! Hi Sun! Hi Moon! Hi Star! Hi Jquery!

Below is the source code:
<html>
<body>
<div class="demo">
<h2>DEMO</h2>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $("i").add("b").css("color","red").css("display","block");
});
</script>
 <i>Hello World!</i>
 <i>Hello Sun!</i>
 <i>Hello Moon!</i>
 <i>Hello Star!</i>
 <i>Hello Jquery!</i>
 <b>Hi World!</b>
 <b>Hi Sun!</b>
 <b>Hi Moon!</b>
 <b>Hi Star!</b>
 <b>Hi Jquery!</b>
 </div>
</body>
</html>

Related Articles
jquery disable button

No comments:

Post a Comment