I am new to jQuery. I want to apply css class to my <li> element but it's not working. Can anyone help me?
My markup is:
<ul class='change'>
<li>companyName</li>
<ul id='uid'>
<li onClick='callTest()'>subcompany</li>
<li onClick='callTest()'>subcompany</li>
<li onClick='callTest()'>subcompany</li>
</ul>
<ul id='uid'>
<li onClick='callTest()'>subcompany2</li>
<li onClick='callTest()'>subcompany2</li>
<li onClick='callTest()'>subcompany2</li>
</ul>
</li>
</ul>
My problem is when I call the callTest() method, I want to change the background color for that <li> i am trying this way not working:
$('#uid li').click(function () {
console.log("call lil...'");
$(this).addClass('selected').siblings().removeClass('selected');
})
It's working fine but the first I selected subcompany it's applied selected class for that and now I selected subcompany2 for this also applied selected class but on this time I want to remove subcompany class. How can I do this?
onclick="callTest()"if you are using jQuery click handlers