I’m creating Divs on the Fly. If I try to get the Attribute id of those Divs, I’m not able to get it.
$("#displayPanel div").click(function (){ alert($(this).attr("id")); }
<div id="displayPanel" class="displayPanel">
<div id="heading"> Display Panel </div> <br/>
<div id="save" class="saveClass"></div> <br/>
<div id="field1" class="my"> </div>
<div id="field2" class="my"> </div>
</div>
Field1 and Field2 are created and appended to the DisplayPanel. And I’m not able to get the id of those divs. But I’m getting the id for those other existing divs
You need to use the live event, the
.click()only works with the elements that are on the page since it got loaded.