my project has generated sets of html elements classes later added. i'd search in sets see if element has class span1hr
followed element has class span0hr
, , if so, change both of classes span1hrfor30mins
.
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>
in case, since programe2
has span1hr
class , programe3
has span0hr
class, want classes changed span1hrfor30mins
.
one additional complication: can see, have multiple sets of row2
- row6
classes, , need search within each set of rows.
i have tried code this, need duplicate row2-3, row3-4, row4-5 , row5-6.
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?
if understand correctly need check class of next element if current element has class.
since using jquery try .next() function. this
$('.pgmfirstrow').each(function(index, element) { element = $(element); if(element.hasclass('span1hr') && element.next().hasclass('span0hr')) { element.removeclass('span1hr').addclass('span1hrfor30mins').next().removeclass('span0hr').addclass('span1hrfor30mins'); } });
Comments
Post a Comment