I've been struggling over this for almost 5 hours and finally I've got a clue.
Here's a code that I'm using on my website:
jQuery(document).ready(function(){
jQuery(".thumbnail").bind("click",function(){
var elem = jQuery(this);
if((elem).data('test')) {
alert('data is test');
elem.data('test',false);
}
else {
alert('data is not test');
elem.data('test',true);
}
});
});
Here's jfiddle.
When you click on "thumbnail" it should fire one alert (either "data is test" or "data is not test").
When I try the same exact code on my WordPress page (localhost) it shows TWO alerts one after another - "data is not set" and then "data is set" - what may cause this strange behavior?
Unfortunately I can't provide the source. I'm hoping this is something common and maybe some jQuery wizard will know the answer? Somehow...?
I don't think it's a jQuery bug, but one of the following:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.