osomanden osomanden - 3 months ago 8
jQuery Question

jquery get value from child <i> rel

Having this code:

<div class='adding_rows'>
<i class='icons-added addRow add' rel='from_agreement_row,agreement_body_rows'></i>
<label>Add Agreement Line</label>

I would like to be able to click on the
adding_rows and in jquery get the value from the
<i rel=''>

Tried :

$(".adding_rows").click(function() {
var from_to_value = $(this).children().attr("rel");

which seems to work on the first instance of
<div class='adding_rows'>

But stops there. Clicking on the next instance warns that "from_to_value is undefined"

Any one?


Works here: https://jsfiddle.net/4hq10p16/

You likely need to delegate if you add new divs to be clicked like this:

$("#container").on("click",".adding_rows",function() {
  var from_to_value = $(this).children().attr("rel");