0

I have a table rows with a unique, where each row has a unique ID. However, sometimes that table is dynamically generated through AJAX.

I also have a button that is meant to update a particular table row bgcolor. But since that table row may be dynamically generated, it doesn't seem to work.

$("input[name=Save]").live("click", function(event){

  //rowID comes from somewhere in the my script

  $.ajax({
  type: "POST",
  url: "./Library/saveStff.php",
  data: $("form").serialize(),
  async: false,
  dataType: "text",
  success: function(value){

  //value will return the color

  //change color
  $(".info_"+rowID).attr('bgcolor', value);
  }
  });

});

'live', 'on', 'bind' seems to work for events only. But I just want to apply it to a attr/bgcolor.

Using

$(".info_"+rowID).live("attr", $(this).('bgcolor', value)); 

also seem invalid.

4

1 に答える 1

2

use css()...try this

$(".info_"+rowID).css('background-color', value);

As of jQuery 1.7, the .live() method is deprecated.

use on()

("input[name=Save]").on("click", function(event){..
于 2013-02-12T20:05:48.380 に答える