jquery - Javascript loop through images attributes -
i have div
on website contains number of images. i'm trying onclick
attribute of each of images within said div
.
<div class="hoi"> <img src="" onclick="alert('hoi')"/> <img src="" onclick="alert('hoi')"/> </div>
i've tried next javascript code:
var count = $(".hoi img").length; for(var = 0; <= count; i++){ alert($('.hoi').find('img').getattribute('onclick')); }
but next error uncaught typeerror: undefined not function
here fiddle http://jsfiddle.net/4lhn0u87/7/
there no method called getattribute()
in jquery object, have .attr(). getattribute() dom api method.
$('.hoi img').each(function(){ console.log($(this).attr('onclick')) })
also iterate through set of elements can utilize .each().
javascript jquery html
No comments:
Post a Comment