Note that there are some explanatory texts on larger screens.

plurals
  1. POChnage CSS onclick function javascript
    primarykey
    data
    text
    <p>i have a code in which when i click on particular element its background should change by removing all other elements background.But the problem here i am getting is when i click on li under ul li ul its taking parent li also and giving background.And Please check my code below</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;meta name="" content=""&gt; &lt;script type="text/javascript" src="jquery-1.3.2.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $("ul li ul li").click(function() { //a = $(this).html(); // when clicking any of these links //alert(a); $("*").removeClass("active"); // remove highlight from all links $(this).addClass("active"); // add highlight to clicked link }) }); &lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $("ul li").click(function() { //a = $(this).html(); // when clicking any of these links //alert(a); $("*").removeClass("active"); // remove highlight from all links $(this).addClass("active"); // add highlight to clicked link }) }); &lt;/script&gt; &lt;style&gt; .active { color:white; background:green; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;ul&gt; &lt;li&gt;level1 &lt;ul&gt; &lt;li&gt;aaa&lt;/li&gt; &lt;li&gt;bbb&lt;/li&gt; &lt;li&gt;ccc&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;level2&lt;/li&gt; &lt;li&gt;level3&lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    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.
 

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