Sunday, 15 January 2012

php - how to change html button class and functionality? -



php - how to change html button class and functionality? -

simply want to change button class , value in order alter button functionality.

what happening value , class changed successfully functionality remain same old class why?!

does browser store jquery code somewhere , load it?! , how can refresh in case??

here's piece of code: (i'm using jquery ajax html , php)

var target_button; // global variable store target button $(".activatebutton").click(function(){ var serial_number = $(target_button).attr("id"); var cvc = $("#cvc").val(); $.ajax({ type: "get", url: '../ajax/tag.php', data: { s: serial_number, c: cvc } }).done(function(data) { var result = jquery.parsejson(data); if (result == "1") { $("#message").text('tag activated'); $("#overlay_form").fadeout(500); $(target_button).attr("value", "disable"); $(target_button).removeclass("popactivatebutton"); //<---------- replacing class $(target_button).addclass("enabledisablebutton"); //<---------- }

here's buttons:

if($tags[$i]['status'] == 1){ $button = "<input type=\"button\" class=\"enabledisablebutton\" id=\"".$tags[$i]['serialnumber']."\" value=\"disable\"/>"; } if($tags[$i]['status'] == 2){ $button = "<input type=\"button\" class=\"popactivatebutton\" id=\"".$tags[$i]['serialnumber']."\" value=\"activate\"/>"; }

when utilize selector selects elements match @ time execute code. called selectors - if cached - not dynamically update when new elements match them added page.

if you've bound event handlers elements, they're going remain there until a. remove event handler(s), or b. remove element entirely. changing class isn't going magically alter event handlers bound.

i'd suggest using event delegation instead:

$(document).on('click', '.enabledisablebutton', function() { //your code enabledisablebutton }).on('click', '.popactivatebutton', function() { // code popactivatebutton });

with event delegation selector checked when event triggered, rather when code executes, will reflect changes page.

note i've used document in code illustration above. however, should instead utilize selector static element (one won't removed) contain elements want execute event handler function for; closer in dom construction dynamic elements better.

php jquery ajax html5

No comments:

Post a Comment