Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery addclass issue
    primarykey
    data
    text
    <p>Here is my html structure</p> <pre><code> &lt;ul&gt; &lt;li&gt;Main 1 &lt;ul&gt; &lt;li&gt;&lt;a href=''&gt;Child 1-1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=''&gt;Child 2-1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=''&gt;Child 3-1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=''&gt;Child 4-1&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;Main 2 &lt;ul&gt; &lt;li&gt;&lt;a href=''&gt;Child 1-2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=''&gt;Child 2-2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href='' class='selected'&gt;Child 3-2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;Child 4-2&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;Main 3&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>Now What I need is that on document.ready jquery checks that which <code>&lt;li&gt;</code>'s <code>&lt;a&gt;</code> has class 'selected'. If it finds one it put class 'mainselected' on its parent <code>&lt;li&gt;</code> and a class 'listul' on it <code>&lt;ul&gt;</code> so that the code will look like that</p> <pre><code>&lt;ul&gt; &lt;li&gt;Main 1 &lt;ul&gt; &lt;li&gt;&lt;a href=''&gt;Child 1-1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=''&gt;Child 2-1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=''&gt;Child 3-1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=''&gt;Child 4-1&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li class='mainselected'&gt;Main 2 &lt;ul class='listul'&gt; &lt;li&gt;&lt;a href=''&gt;Child 1-2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=''&gt;Child 2-2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href='' class='selected'&gt;Child 3-2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;Child 4-2&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;Main 3&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>Can anyone please give me a jquery code for this.</p> <p>Thanks</p>
    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.
    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