Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging class of all class="like" inside a <div> with particular data-id
    primarykey
    data
    text
    <p>I'm stuck with changing the class of all the <code>class=like</code> spans that are within <code>&lt;div class="h2" data-id="9"&gt;</code> (one for this example only. There are more on the page).</p> <p>I need this <code>$('.h2[data-id="9"]')</code> just this way, since I need to pick out particular <code>div</code>s.</p> <p>This being the case, how can I change the <code>class</code> of all <code>class=like</code> to something else. I seem to be going no where with this. You'll see what I'm trying to achieve if you look at my code below.</p> <p>Can you pls help?</p> <pre><code>success: function(data){ // Remove class like, add class no-link $('.like[data-id="'+data+'"]').removeClass('like').addClass('no-like'); //For this example $('.h2[data-id="9"]').siblings().removeClass('like').addClass('grey'); }, </code></pre> <p>My <code>&lt;div&gt;</code></p> <pre><code>&lt;div class="h1" data-id="8"&gt;Restaurants&lt;/div&gt; &lt;div class="h2" data-id="9"&gt;Which is your favourtie restaurant in town? &lt;div&gt;* McDonalds &amp;nbsp &lt;span class="like" data-id="10" data-sec="9"&gt;Like&lt;/span&gt;&lt;/div&gt; &lt;div&gt;* KFC &amp;nbsp &lt;span class="like" data-id="11" data-sec="9"&gt;Like&lt;/span&gt;&lt;/div&gt; &lt;div&gt;* The Heart Attack Grill &amp;nbsp &lt;span class="like" data-id="12" data-sec="9"&gt;Like&lt;/span&gt;&lt;/div&gt; &lt;div&gt;* In-n-Out &amp;nbsp &lt;span class="like" data-id="13" data-sec="9"&gt;Like&lt;/span&gt;&lt;/div&gt; &lt;div&gt;* Popeye's &amp;nbsp &lt;span class="like" data-id="14" data-sec="9"&gt;Like&lt;/span&gt;&lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload