Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<div id=id1>
<input class=class1>
</div>

<div id=id2>
<input class=class1>
</div>


Above is my html tags.
in below code i have select the parent id like this,

$(".class1").parent().attr('id')


but i am getting id1 only .i want both id1 and id2. ??
what to do ?
Posted

JavaScript
var pIds=[];
$(".class1").each(function() {
    pIds.push($(this).attr("id"));
});
 
Share this answer
 
Try this

JavaScript
$(".class1").parent().each(function (i, e) {
              var id = e.id;
              alert(id);
          })
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900