javascript - Simplifying js for a dropdown -
I have a pretty basic code for a dropdown HTML code, as it works but to make it easier Is this a JS code?
$ (document) .ready (function () {var n = ".dropdown-menu", no = 'drop'; $ ('.downloaddown') Click (function () {If ($ (n) .hasClass (no)) {$ (n) .removeClass (no);} else {$ (n) .addClass (no);}}). Mouseover (function () {$ (n ) .addClass (no);}). Mouseout (function () {if ($ (n) .mouseover ()) {$ (n) .removeClass (no);}})}); Please note that I know that I can add only one row to CSS itself . So there is no question. #navigation-top #navigation holder Lee: hover & gt; Ul {display: block; }
We can use toggleclass instead of add / remove class. In the code below, we can check that if you check and call directly callclass
if ($ (n) .mouseover ()) {$ (n) .removeClass (no) ; } So the last customized code like this:
$ ('. Dropdown'). Click (function () {$ (n) .toggleClass (no);}) mouseover (function () {$ (n) .addClass (no);}). Mouseout (function () {$ (n) .removeClass (no);})
Comments
Post a Comment