Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Looping through Array and finding the not selected items
    primarykey
    data
    text
    <p><strong>My CodePen:</strong> <a href="http://codepen.io/leongaban/pen/IGcBa" rel="nofollow noreferrer">http://codepen.io/leongaban/pen/IGcBa</a></p> <p>I have an Array which contains 5 items:</p> <pre><code>var home = { faqmenu : ['faq-general', 'faq-protecting', 'faq-search', 'faq-incoming', 'faq-requests'] }; </code></pre> <p><br/> And my simple list menu in my markup, I'm using the tag <code>data-pane</code> to signal which button is clicked. Then in my jQuery <code>faqpane = $(this).data('pane');</code> is how it finds out what button is clicked. <br/><br/></p> <pre><code>&lt;li id="faq-general" data-pane="faq-general" class="faq-menu-item faq-blue"&gt; &lt;span&gt;General Questions&lt;/span&gt; &lt;/li&gt; &lt;li id="faq-protecting" data-pane="faq-protecting" class="faq-menu-item"&gt; &lt;span&gt;Protecting Your Data&lt;/span&gt; &lt;/li&gt; ... </code></pre> <p><img src="https://i.stack.imgur.com/VLuGP.png" alt="enter image description here"></p> <p>And I'm trying building a simple Case Switch function which will find out which button is clicked, now with that information I need to perform some actions on the button that was clicked as well as the items that were not clicked.</p> <p>It's easy to do stuff to the button that was clicked, <strong>but how do I target all the other items that were NOT clicked and change their CSS?</strong></p> <pre><code>$('.faq-menu-item').click(faqMenuShow); function faqMenuShow(event) { faqpane = $(this).data('pane'); console.log('The clicked faqpane is: '+faqpane); switch (faqpane) { case 'faq-general': // Do stuff on the faq-general button - easy jQuery.each(home.faqmenu, function(index, value) { console.log(this); return (this != "faq-general"); }); // ^ For items that are NOT faq-general // remove this class: .parent().removeClass('faq-blue'); break; case 'faq-protecting': break; case 'faq-search': break; case 'faq-incoming': break; case 'faq-requests': break; } }; </code></pre> <p><br/> My <code>console.log(this);</code> in the <code>jQuery each</code> function spits this out in the console: <img src="https://i.stack.imgur.com/0OuUB.png" alt="enter image description here"></p> <p>How would you go about finding the items that were not selected and running some basic functions like removing classes / css on them?</p> <p><strong>My CodePen:</strong> <a href="http://codepen.io/leongaban/pen/IGcBa" rel="nofollow noreferrer">http://codepen.io/leongaban/pen/IGcBa</a></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.
 

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