highlight table row after dynamically adding it

后端 未结 2 803
南旧
南旧 2021-01-21 12:58

looking at how i can highlight a table row after dynamically adding it with jquery my code seems to be adding the row with no problems, but its not highlighting the correct row<

相关标签:
2条回答
  • 2021-01-21 13:34

    I would assume that the effect would be applied to what ever tr:last was as that is the main selector.

    after() returns the jQuery object from the original selector $('#opponents tr:last') allowing you to continue chaining on to that main selector.


    DEMO - Using existing code, wrong row is highlighted


    Try separating the new row into it's own instead and applying the effect to it directly. Similar to this:

    var $newRow = $('<tr><td>data</td><td>more data</td></tr>');
    
    $('#opponents tr:last').after($newRow);
    $newRow.effect("highlight", {}, 3000);
    

    DEMO - Working DEMO of above code


    0 讨论(0)
  • 2021-01-21 13:45

    You have to add css in effects like follow:

    $('#opponents tr:last').after('<tr><td>data</td><td>more data</td></tr>').effect("highlight", {color:'#ff0000'}, 3000);
    
    0 讨论(0)
提交回复
热议问题