I need to have a for
loop inside my jQuery.
Example:
for(i=0;i<counter;i++)
{
$("div"+i+"").click(function(){//some code});
}
How can I accomplish this?
EDIT:
This code was posted by the OP in a comment to one of the answers:
$("#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">
<label id="labelstr1">Untitled1</label>
<input id="inputstr1" type="text"/>
</div>
<div id="field2" class="my">
<label id="labelstr2">Untitled1</label>
<input id="inputstr2" type="text"/>
</div>
</div>
The alert is showing me the id for the first two div
s and not for the field1
and field2
.
Note:
The Field1
and Field2
div
s are created on the fly.