<div>'.$i.'</div>
$i is auto generated by loop – which could lead to:
<div>'.$i.'</div>
<div>'.$i.'</div>
<div>'.$i.'</div>
etc. where each $i is different.
How do I get value of particular $i (using jQuery), when div is clicked.
In standard JS I would use onClick($i).
In jQuery I just do not know, how to pick that val.
If you don’t have any other way to identify the
<div>elements, this would place a handler on every<div>on the page.The
.text()method will return the text content for that<div>, (as well as any nested elements).If you only wanted the
clickevent on certain<div>elements, the best is to add a class, and select the correct ones based on that.HTML
If the
<div>elements are all within the same ancestor element, you could use.delegate()instead, which will place one handler on the ancestor to handle all divs inside.HTML
(Requires jQuery 1.4 or later)