title: jquery id selection change class
body: <pre><code>$('#sidebar ul li ul li').click(function () {
          var ids = $(this).attr('id');
          $('#ids').addClass('active');
          $('#ids').parent('ul').parent('li').addClass('has-sub active');
          alert(ids); // Will alert the id if the element has one    
      });
  </code></pre>
  
  <p>I didn't understand why this is not working. <code>alert</code> gives me the id of the <code>li</code> element but the 2 lines before it don't work I mean these 2:</p>
  
  <pre><code>$('#ids').addClass('active');
  $('#ids').parent('ul').parent('li').addClass('has-sub active');
  </code></pre>
  
  <p>Where is the problem? Am I missing something? </p>
  
  <p><img src="https://i.stack.imgur.com/Oly49.png" alt="enter image description here"></p>