I was trying to answer this question: Find specific anchor tag and replace data atribute on click and I created this jsfiddle which attempts to select an anchor element based on a data attribute.
I want to trap events on this anchor based on specific data attributes.
<a href="#" class="article-play" data-play="4">click</a>
JS
//this event only fires if 'data-pause' is initially specified in the anchor element
$(".article-play[data-pause]").on("click", function() {
$(this).removeAttr("data-pause");
$(this).attr("data-play",4);
$("#output").text("playing 4");
});
//this event only fires if 'data-play' is initially specified in the anchor element
$(".article-play[data-play]").on("click", function() {
$(this).removeAttr("data-play");
$(this).attr("data-pause",3);
$("#output").text("pausing 3");
});
Is this expected behavior? A bug in jQuery? Something else?
onwas meant to be a replacement forlivewhich allowed us to bind to dynamic elements