I searched the answer, but I think what should be done here. > I have 3 lee tags, each of which has a drop below I want to change the background color on active Li, then remove it if I click on NAIL or active active Li. Has been added, but it has been removed only by clicking on it. I recently clicked active Li is clicked and it is also closed, so the need to remove the square The Ykta.
Thank you.
& lt; Style & gt; .add_color {background: # F3A54E; Color: #FFF! Important;} & lt; / Style & gt; & Lt; Body & gt; & Lt; Ul class = "submenu" & gt; & Lt; Li & gt; Shopping by category & lt; Ul & gt; & Lt; Li & gt; Some text & lt; / Li & gt; & Lt; Li & gt; Some text & lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; Li & gt; Shop by brand & lt; Ul & gt; & Lt; Li & gt; Some text & lt; / Li & gt; & Lt; Li & gt; Some text & lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; Li & gt; Diet Specification & lt; Ul & gt; & Lt; Li & gt; Some text & lt; / Li & gt; & Lt; Li & gt; Some text & lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Body & gt; & Lt; Script & gt; // Click the sub menu drop down menu $ (document) .ready (function () {$ ("li"). Click (function () {// Add background color and remove. $ ("Ul.SubMenu Li ") .removeClass (" add_color "); $ (this) .toggleClass (" add_color "); // toggle the child, but do not include them in the hide selector .not () $ ('li & gt; ul ') .Note ($ (this). Children ("UL"). Slide Toggle (400)) SlideUp (400);});}); & Lt; / Script & gt;
The problem is that you remove the class from all li Before calling the code, toggleclass () means that when toggleclass () is executed then the class is removed from the current element, whose The resulting class <<>
$ (document) .ready (function () {$ (". Submenu "; li) Function (e) {// Add background color and remove. $ ("Ul.SubMenu li.add_color"). (Not this) .removeClass ("add_color"); $ (this) .toggleClass ("add_color"); / Do not include / hide children but do not include them in the selector.not () $ ('submenu le' gt; ul '). ($ (This). Children ("UL"). Slide Toggle (400)) SlideUp ( 400);});}); .add_color {background: # F3A54E; Color: #FFF! Important; } & lt; Script src = "https://ajax.googleapis.com/ajax/libs/JQuery/1.11.1/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Ul class = "submenu" & gt; & Lt; Li & gt; Shopping by category & lt; Ul & gt; & Lt; Li & gt; Some text & lt; / Li & gt; & Lt; Li & gt; Some text & lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; Li & gt; Shop by brand & lt; Ul & gt; & Lt; Li & gt; Some text & lt; / Li & gt; & Lt; Li & gt; Some text & lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; Li & gt; Diet Specification & lt; Ul & gt; & Lt; Li & gt; Some text & lt; / Li & gt; & Lt; Li & gt; Some text & lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; / Ul & gt;
No comments:
Post a Comment