Hi there,
I'm having an issue with jQuery. I have an element, which contents I replace. However, I also replace the data-action attribute with another value. However, when I click on the element again, it still runs the code with the previous data-action attribute value. Is there a way to force jQuery to use the new one? Is this what I want even possible?
I Tried .data()
, but with the same result.
jQuery
$('#selector li').click(function() {
var action = $(this).data("action");
var item = $(".item").data("id");
$.ajax({
type: "POST",
data: "ticket=" + item,
url: "/run/" + action,
success: function(data) {
var jsonObj = jQuery.parseJSON(data);
if (jsonObj.valid == 'true') {
if (action == 'pick') {
$('li[data-action=pick]').html('Release').attr('data-action', 'release');
} else if (action == 'release') {
$('li[data-action=release]').html('Pick').attr('data-action', 'pick');
}
}
}
});
});
HTML
<li data-action="pick">Pick</li>
Edit: I just think my previous comment was a bit unclear. I Want to change the attribute, which it does. However, when I click the element again, it still recognizes the previous attribute, and not the new one, thus not running the correct action.