AddClass using .live () with jQuery

I am currently using a function .load()to dynamically load content into a container div. The downloadable content is the table data that I would like to use for the zebra stripes. The zebra stripe is simple on a static page, but I cannot figure out how the zebra stripe loads new content into a container div.

Here is the code I'm trying to work with:

$("table tbody tr:even").live("EVENT", function(){
  $(this).addClass("alt");
});

"EVENT" should not be "click"either "mouseover", but "onload" or something like that. Is there any way to do this? Thanks for your suggestions!

~ Jared

+3
source share
4 answers

load().

$("#myDiv").load( "/somecontroller/someaction", { data: value }, function() {
    $("#myDiv").find( "table tbody tr:even" ).addClass( "alt" );
});
+7

tvanfosson ( ), live() . http://api.jquery.com/:

: click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress, keyup

: blur, focus, mouseenter, mouseleave, change, submit

0

, . ? css . ,

$("table tbody tr:even").removeClass("alt").addClass("alt");
0

, jquery 1.4.2

$( "body" ). live ( "mousemove", function() {$ ( ". zebra tr: nth-child (even)" ). addClass ( "alt" );});

-1

Source: https://habr.com/ru/post/1721911/


All Articles