my project has generated sets of html elements classes. search in sets see if element has class span1hr next element has class span0hr, change class span1hr span1hrfor30mins each row using loops.
here's sample of html elements like:
<div id="programe1" class="pgmfirstrow div_1_2 row2"></div> <div id="programe2" class="pgmfirstrow div_1_3 row3 span1hr">ncis</div> <div id="programe3" class="pgmfirstrow div_1_4 row4 span0hr">cbs evening news scott pelley</div> <div id="programe4" class="pgmfirstrow div_1_5 row5 span1hr">ncis: los angeles</div> <div id="programe5" class="pgmfirstrow div_1_6 row6">person of interest</div> <div id="programe6" class="pgmfirstrow div_2_2 row2 span1hr">twisted</div> <div id="programe7" class="pgmfirstrow div_2_3 row3 span1hr">pretty little liars</div> <div id="programe8" class="pgmfirstrow div_2_4 row4 span1hr">pretty little liars</div> <div id="programe9" class="pgmfirstrow div_2_5 row5 span1hr">twisted</div> <div id="programe10" class="pgmfirstrow div_2_6 row6 span1hr">pretty little liars</div> <div id="programe11" class="pgmfirstrow div_3_2 row2 span1hr">cnn newsroom</div> <div id="programe12" class="pgmfirstrow div_3_3 row3 span1hr">around world</div> <div id="programe13" class="pgmfirstrow div_3_4 row4 span0hr">cnn newsroom</div> <div id="programe14" class="pgmfirstrow div_3_5 row5 span2hr">cnn newsroom</div> <div id="programe15" class="pgmfirstrow div_3_6 row6 span1hr">the lead jake tapper</div> in case, since programe2 , programe12 has span1hr class, programe3 , programe14 has span0hr class, find on sets on each row3 class span1hr next row4 class span0hr change class in each row3 change span1hr span1hrfor30mins while class span0hr in row4 remains unchanged. other classes in programe7 , programe8 has class 'span1hr' don't match in programe2 , programe12, want ignore it.
i have tried code this, search every sets of row3 in html without checking on 2 different sets row3 , row4 change class.
if ($('.span1hr').hasclass('row3') && $('.span0hr').hasclass('row4')) { $('.span1hr').each(function (i, e) { if ($(e).hasclass('row3') && $(e).hasclass('.span1hr')) { $(e).attr('row3'); $(e).removeclass('span1hr').addclass('span1hrfor30mins'); } }); } does know how can this?
it can more simple that, if understanding issue correctly (admittedly, had read through logic number of times before felt understood looking :d ). should work:
$(".row3.span1hr + .row4.span0hr").each(function(){ $(this).prev().addclass("span1hrfor30mins").removeclass("span1hr"); }); that grab of elements had both row4 , span0hr classes and occurred after element row3 , span1hr classes. step first element (i.e., .row3.span1hr element) using .prev(), add span1hrfor30mins class, , remove span1hr class.
Comments
Post a Comment