Reputation: 13
I can only get the input
tag but I also hope to get the textarea
tag. How can I do that?
<div class="common-div">
<input type="text" name="confirm-pwd"/>
<textarea cols="150" rows="5"></textarea>
</div>
<script>
$(".common-div input").each(function() {}):
</script>
Upvotes: 0
Views: 255
Reputation: 3
you can find all the element inside a div by-
$(".common-div").find("*").each(function() {});
But it will return all other types of element in such as span, div, input, button Etc.
So if you want to get only input type where user can input text-
$(".common-div").find(":input").each(function() {});
Upvotes: 0
Reputation: 455
$('#div').children.click(function(){
//your code goes here..
});
may be this helps you out-
Upvotes: 1
Reputation: 26380
To grab all the elements in a container, there are many ways. For instance :
$(".common-div *")
or $(".common-div").find("*")
or $(".common-div").children()
Upvotes: 1
Reputation: 9430
You can enumerate them after comma:
$(".common-div input, .common-div textarea").each(function(){}):
Or, as @epascarello pointed out in a comment, use common class name for those elements you want to modify with jQuery.
Upvotes: 5