Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding classes for items inside wrap
    text
    copied!<p>I have this code:</p> <pre><code>$(".feed-item .field-content p").each(function(i) { $(this).addClass("item" + (i+1)); }); </code></pre> <p>This code help me to add classes in paragraph inside this markup:</p> <pre><code>&lt;div class="feed-item"&gt; &lt;div class="field-content"&gt; &lt;p&gt;This must be class item1&lt;/p&gt; &lt;p&gt;This must be class item2&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="feed-item"&gt; &lt;div class="field-content"&gt; &lt;p&gt;This must be class item1&lt;/p&gt; &lt;p&gt;This must be class item2&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>But I need that always the count start on number 1. Have I explained well? Now I get this result:</p> <pre><code>&lt;div class="feed-item"&gt; &lt;div class="field-content"&gt; &lt;p class="item1"&gt;This must be class item1&lt;/p&gt; &lt;p class="item2"&gt;This must be class item2&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="feed-item"&gt; &lt;div class="field-content"&gt; &lt;p class="item3"&gt;This must be class item1&lt;/p&gt; &lt;p class="item4"&gt;This must be class item2&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>And this is that I needed (note the difference is in the class associated with the p tags in the second field-content div):</p> <pre><code>&lt;div class="feed-item"&gt; &lt;div class="field-content"&gt; &lt;p class="item1"&gt;This must be class item1&lt;/p&gt; &lt;p class="item2"&gt;This must be class item2&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="feed-item"&gt; &lt;div class="field-content"&gt; &lt;p class="item1"&gt;This must be class item1&lt;/p&gt; &lt;p class="item2"&gt;This must be class item2&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>I'm working on this link: <a href="http://jsfiddle.net/bosspetta/RJkP5/" rel="nofollow">http://jsfiddle.net/bosspetta/RJkP5/</a></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