Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery Selecting an element in a div based on text in a span
    text
    copied!<p>The Markup:</p> <pre><code>&lt;div class="day"&gt; &lt;span&gt;1&lt;/span&gt; &lt;div class="icon-shop icon-blank"&gt;&lt;p class="event-details" id="shop-1"&gt;&lt;/p&gt;&lt;/div&gt; &lt;div class="icon-eat icon-blank"&gt;&lt;p class="event-details" id="eat-1"&gt;&lt;/p&gt;&lt;/div&gt; &lt;div class="icon-fun icon-blank"&gt;&lt;p class="event-details" id="fun-1"&gt;&lt;/p&gt;&lt;/div&gt; &lt;div class="icon-scoop icon-blank"&gt;&lt;p class="event-details" id="scoop-1"&gt;&lt;/p&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="day"&gt; &lt;span&gt;2&lt;/span&gt; &lt;div class="icon-shop icon-blank"&gt;&lt;p class="event-details" id="shop-2"&gt;&lt;/p&gt;&lt;/div&gt; &lt;div class="icon-eat icon-blank"&gt;&lt;p class="event-details" id="eat-2"&gt;&lt;/p&gt;&lt;/div&gt; &lt;div class="icon-fun icon-blank"&gt;&lt;p class="event-details" id="fun-2"&gt;&lt;/p&gt;&lt;/div&gt; &lt;div class="icon-scoop icon-blank"&gt;&lt;p class="event-details" id="scoop-2"&gt;&lt;/p&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>This is for a calendar and I am pulling in event data. </p> <p>An example: If an event is on day 2 in the shop category , I then need to remove class .icon-blank from:</p> <pre><code>&lt;div class="icon-shop icon-blank"&gt;&lt;p class="event-details" id="shop-2"&gt;&lt;/p&gt;&lt;/div&gt; </code></pre> <p>needs to become</p> <pre><code>&lt;div class="icon-shop"&gt;&lt;p class="event-details" id="shop-2"&gt;&lt;/p&gt;&lt;/div&gt; </code></pre> <p>This is what im trying to do: I have the event on day 2 in the shop category.</p> <pre><code>var cat = 'shop'; var day = '2'; $(".day").find("span:contains('" + day + "') &gt; .icon-" + cat).removeClass('icon-blank'); </code></pre> <p>The code above I am trying to select the proper day div(the day with a span with the text "2" and then select the div .icon-shop within that day. If that makes any sense at all lol. Thanks for your help!</p>
 

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