jquery on each bind text for parent attribute name values -


i trying own tooltip, should show value of parent element name value:

i appending new div after anchor tag, , try bind text value of parent anchor name value...

but getting last name value(tooltip 3333333333333) in (.tooltipcontainer) div ? can 1 resolve?

html:             <!-- tooltip - begin  -->             <ul>                 <li><a name="tooltip 1111111111111" class="customtooltip">tool tip 1111</a></li>                 <li><a name="tooltip 2222222222222" class="customtooltip">tool tip 222</a></li>                 <li><a name="tooltip 3333333333333" class="customtooltip">tool tip 333333</a></li>             </ul>             <!-- tooltip  end  -->        js:     $(document).ready( function() {          $(".customtooltip").each(function(i){             var customtooltipname = $(this).attr('name');             var parentattrnamevalue = $(this).parent().find(".customtooltip").attr('name');         //  alert(parentattrnamevalue);              $(this).after('<div class="tooltipcontainer"></div>');             $(".tooltipcontainer").html(parentattrnamevalue);         });     });  

the problem $(".tooltipcontainer") gets elements class tooltipcontainer instead of added 1 , sets html parentattrnamevalue value, when last item processed value set elements.

instead can add element given below, here set html new element when being created.

$(document).ready(function () {     $(".customtooltip").each(function (i) {         var customtooltipname = $(this).attr('name');         var parentattrnamevalue = $(this).parent().find(".customtooltip").attr('name');         //  alert(parentattrnamevalue);          $('<div />', {             html: parentattrnamevalue, 'class': 'tooltipcontainer'         }).insertafter(this);     }); }); 

demo: fiddle

also not sure parentattrnamevalue, same customtooltipname


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -