I have a div on my website which contains a number of images. I'm trying to get the onclick attribute of each of the images inside said div.
<div class="hoi">
<img src="" onclick="alert('hoi')"/>
<img src="" onclick="alert('hoi')"/>
</div>
I've tried the following Javascript code:
var count = $(".hoi img").length;
for(var i = 0; i <= count; i++){
alert($('.hoi').find('img').getAttribute('onclick'));
}
But I get the following error Uncaught TypeError: undefined is not a function
Here is a fiddle http://jsfiddle.net/4Lhn0u87/7/
find('img').attr('onclick')orfind('img')[0].getAttribute('onclick')