title: add "active "class to the selected list item through javascript
body: <p>I have a class name "active" which i want to be added to the selected list item. </p>
  
  <p>Here is how my list style looks like:</p>
  
  <pre><code>&lt;ul class="page-sidebar-menu"&gt;
  
  &lt;li class="start active"&gt;
                      &lt;a href="dashboard.php"&gt;&lt;span class="title"&gt;Dashboard&lt;/span&gt;&lt;/a&gt;
                  &lt;/li&gt;
                  &lt;li &gt;
                      &lt;a href="javascript:;"&gt;&lt;span class="title"&gt;Pages&lt;/span&gt;&lt;/a&gt;
                      &lt;ul class="sub-menu"&gt;
                          &lt;li &gt;
                              &lt;a href="all-pages.php"&gt;All Page&lt;/a&gt;
                          &lt;/li&gt;
                          &lt;li &gt;
                              &lt;a href="add-page.php"&gt;Add Page&lt;/a&gt;
                          &lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/li&gt;
  
                &lt;li&gt;
                      &lt;a href="javascript:;"&gt;&lt;span class="title"&gt;Posts&lt;/span&gt;&lt;/a&gt;
                      &lt;ul class="sub-menu"&gt;
                          &lt;li &gt;
                              &lt;a href="all-posts.php"&gt;All Posts&lt;/a&gt;
                          &lt;/li&gt;
                          &lt;li &gt;
                              &lt;a href="add-posts.php"&gt;Add Posts&lt;/a&gt;
                          &lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/li&gt;
  
  &lt;/ul&gt;
  </code></pre>
  
  <p>i want to add class on two places one is "li" under sub-menu and <code>&lt;span class="title"&gt;Posts&lt;/span&gt;</code></p>
  
  <p>It should look something like this
  <img src="https://i.stack.imgur.com/NEkdZ.png" alt="enter image description here"></p>
  
  <p>I tried something like this but didnt work</p>
  
  <pre><code>$('.page-sidebar-menu ul li a').click(function() {
                $('.page-sidebar-menu ul li').removeClass('active');    
                $(this).addClass('active');
              }); 
  </code></pre>
  
  <p>Please suggest some solution.</p>
  
  <p>Thank you!</p>