zhaoyunxing
zhaoyunxing

Reputation: 13

How to get all the elements inside of a div

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

Answers (4)

KdCoder
KdCoder

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

payal_suthar
payal_suthar

Reputation: 455

$('#div').children.click(function(){
//your code goes here..
});

may be this helps you out-

Upvotes: 1

Jeremy Thille
Jeremy Thille

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

n-dru
n-dru

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

Related Questions