Recently I was discussing something with friend about jQuery and question comes from friend that how we can select the all p in Div with jQuery. With jQuery selector its very easy to select all p in div tag. But from this conversation I came to know that lots of people does not know about it. So I thought it will be great idea to write a blog post about it.
As you know with jQuery selectors we can have single selection but lots of people does not know that jQuery is also provide multiple selection also. Let’s take an example. You have following html structure.
Now you want to select all your p tag in div then you can write jQuery selectors chain like following.
It will select all the P tags now you can assign class to that p tag or manipulate the that array in the way you want. This is not only true for P tag for any tags you can have select all the similar tags. That’s it. Its very easy hope you like it. Stay tuned for more..
As you know with jQuery selectors we can have single selection but lots of people does not know that jQuery is also provide multiple selection also. Let’s take an example. You have following html structure.
<div id="test> <p>Jalpesh Vadgama</p> <p>Vishal Vadgama</p> </div>
Now you want to select all your p tag in div then you can write jQuery selectors chain like following.
var allp= $('div#test p');
It will select all the P tags now you can assign class to that p tag or manipulate the that array in the way you want. This is not only true for P tag for any tags you can have select all the similar tags. That’s it. Its very easy hope you like it. Stay tuned for more..
0 comments:
Post a Comment
Your feedback is very important to me. Please provide your feedback via putting comments.