Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery change background/css class onclick of image clicked and others
    primarykey
    data
    text
    <p>I have a question regarding jQuery. I have multiple images that are, in essence, the same. The difference is that one of the images (let's call it the 'active' image) is a used as a side navigation bar which triggers "animated collapse" of the multiple DIVs in the Div to the right. For this item which is clicked (and triggers the animated collapse) I am wanting to change the background image which has been defined in CSS.</p> <p>I'd love it if I could get the "active" background/class to be displayed on the one, while the "inactive" icons revert to the "inactive status" onclick. As you select different items in the nav bar, each one changes it's background/class to the active designation, along with triggering the animated collapse effect.</p> <p>Right now only the animatedcollapse event works, though the inactive status</p> <p>Here's the HTML that I'm working with:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="animatedcollapse.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; animatedcollapse.addDiv('one', 'fade=1,speed=400,group=content,hide=0') animatedcollapse.addDiv('two', 'fade=1,speed=400,group=content,hide=1') animatedcollapse.addDiv('three', 'fade=1,speed=400,group=content,hide=1') animatedcollapse.init() &lt;/script&gt; &lt;script type="text/javascript"&gt; $('a.toggle').click(function () { $('a.toggle.select').removeClass('active'); $(this).addClass('active'); }); &lt;/script&gt; &lt;style type="text/css"&gt; a.toggle { background-image: url(images/contentnav_inactive.png); width: 275px; height: 41px; background-position: left top; background-repeat: no-repeat; float: left; margin-top: 5px; margin-bottom: 5px; } a.toggle.active { background-image: url(images/contentnav_active.png); width: 275px; height: 41px; background-position: left top; background-repeat: no-repeat; float: left; margin-top: 5px; margin-bottom: 5px; } a.contentheader { height: 25px; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="content"&gt; &lt;div class="contentnav"&gt; &lt;a class="contentheader" href="javascript:animatedcollapse.toggle('one')" id="toggle1_TGLink"&gt;&lt;img src="images/contnav_header_business.png" width="252" height="25" style="margin: 2px 4px" /&gt;&lt;/a&gt; &lt;a class="toggle" id="toggle2_TGLink" href="javascript:animatedcollapse.toggle('two')"&gt;&lt;img src="images/contentnav_text_busauto.png" width="269" height="41" /&gt;&lt;/a&gt; &lt;a class="toggle" href="javascript:animatedcollapse.toggle('three')" id="toggle3_TGLink" &gt;&lt;img src="images/contentnav_text_bop.png" width="269" height="41" /&gt;&lt;/a&gt; &lt;/div&gt; &lt;div class="toggle&gt;&lt;/div&gt; &lt;div class="contenttext"&gt; &lt;div id="one" class="TG_hidden"&gt;&lt;h1&gt;Business Insurance Overview&lt;/h1&gt; &lt;hr /&gt; &lt;/div&gt; &lt;div id="two" class="TG_hidden"&gt;&lt;h1&gt;Business Auto&lt;/h1&gt; &lt;hr /&gt; &lt;/div&gt; &lt;div id="three" class="TG_hidden"&gt;&lt;h1&gt;Business Owners Insurance (BOP)&lt;/h1&gt; &lt;hr /&gt; &lt;/div&gt; &lt;/div&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.
    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