The HTML:
<a href="#" class="change">Old Text</a>
<a href="#" class="change">Old Text</a>
I want to change the "Text" with jQuery, delay two seconds and set it back to the original. I've tried timeout and delay unsuccessfully. The page has multipe items that have the same text "Add to cart", and switch to "Added", then back again.
The jQuery:
$('.change').html('first').delay(2000).html('second')
This fails. It ignores the first, and skips right to the second
_x = $(this);
$(_x).html('New Text');
_t = setTimeout(function(){
$(_x).html('Old Text');
},2000);
This works, if the user clicks and doesn't trigger another before the 2 second reset. If someone clicks #1 and then clicks #2 before #1 has the text reset, it works on #2 but the text on #1 stays with the New Text.
I thought that since it's inside a function, that the timeout would be instantiated for each object with it's own instance of _t, but apparently not.
I'm not sure if it matters, but the elements are sometimes loaded dynamically, and the click binding is set accordingly
$(element).on('click','.change',function(_e) { ...
How can I handle this? Thank you in advance.