Here is my code.
//generate a id $(".slide_img_a").each(function(){ $(this).attr("id","img"+(Math.round(Math.random()*100))) }); // get id var img_id = $(".slide_img_a").attr("id"); // alert the id $(".slide_img_a img").hover(function(){ alert(img_id); });
The problem of this is I have a 5 images with the same class and random id. When I hover the image, the result is he can only alert the id of first image. I wanted to do is when I hover them they will alert thier own id's