I have the following images:-
<img rel="item-1" src="1.gif"/>
<img rel="item-2" src="2.gif"/>
<img rel="item-3" src="3.gif"/>
and at the moment I can use Jquery to attach a click event to each image like so:-
$("img[rel^='item']").click(function () {
var img = $(this);
});
Suppose I want to use the data attribute and remove the rel attribute:-
<img data-thumb="item-1" src="1.gif"/>
<img data-thumb="item-2" src="2.gif"/>
<img data-thumb="item-3" src="3.gif"/>
What would my jquery look like to attach a click event to each image that has the data-thumb attribute?
EDIT Sorry guys it is the same, like an idiot I forgot to change this in my code:-
var url = img.attr('rel'); to var url = img.data('thumb');
I feel ashamed!