jquery - Changing class of all class="like" inside a <div> with particular data-id -


i'm stuck changing class of class=like spans within <div class="h2" data-id="9"> (one example only. there more on page).

i need $('.h2[data-id="9"]') way, since need pick out particular divs.

this being case, how can change class of class=like else. seem going no this. you'll see i'm trying achieve if @ code below.

can pls help?

success: function(data){          // remove class like, add class no-link          $('.like[data-id="'+data+'"]').removeclass('like').addclass('no-like');      //for example     $('.h2[data-id="9"]').siblings().removeclass('like').addclass('grey');     }, 

my <div>

<div class="h1" data-id="8">restaurants</div>         <div class="h2" data-id="9">which favourtie restaurant in town?             <div>* mcdonalds &nbsp              <span class="like" data-id="10" data-sec="9">like</span></div>             <div>* kfc &nbsp                    <span class="like" data-id="11" data-sec="9">like</span></div>             <div>* heart attack grill &nbsp <span class="like" data-id="12" data-sec="9">like</span></div>             <div>* in-n-out &nbsp               <span class="like" data-id="13" data-sec="9">like</span></div>             <div>* popeye's &nbsp               <span class="like" data-id="14" data-sec="9">like</span></div>         </div> 

give shot:

function classreplace(data,replacementclass) {         //$('.h2[data-id="' + data + '"]').children('div').children('span[data-sec="' + data + '"]').removeclass('like').addclass(replacementclass);   $('.h2[data-id="'+ data +'"]').children('div').children('span.like').removeclass('like').addclass(replacementclass); };  classreplace(9,'hide'); 

just pass in data-id want replace.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -