Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery - if element has particular CSS attribute, execute script
    primarykey
    data
    text
    <p>I have a menu that contains a bunch of toggles. Each item toggles something different.</p> <p>I am trying to make an overall "reset" button that resets several things back to some default settings. I need to detect if a menu item is toggled or not, and if so, execute some code on that particular item and if not, do nothing. With an item is toggled on, it gets a CSS background color, demonstrated below, so I came up with the following reset code:</p> <pre><code>$('#app-menu ul.dynamic-items li ul li').toggle(function () { $(this).css({background: "#4c581e"}); }, function () { $(this).css({background: "none"}); }); /* Reset Button */ $(".reset").click(function() { if( $('#app-menu ul.dynamic-items li').css({background: "#4c581e"}) != null ) { $(this).click(); /* If the item has the background code mentioned above, it is toggled on, therefore this "click" should reset its state */ } else { // do nothing // }; }); </code></pre> <p>Basically I am trying to say that, if a menu item has the #4c581e background, that means its toggled on, and therefore it should be "clicked" to toggle it off again.</p> <p>Problem is, its not working. I am fairly new-ish to jQuery so I figured I am doing something wrong.</p> <p>Any ideas folks?</p> <p>EDIT: I just want to note that the menu items actually toggle DIV elements on the page, so its not just a matter of resetting the menu item's css style. This is why I tried to make it "click" the item if the particular CSS property is detected, because "clicking" it will basically toggle it off again.</p>
    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.
    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