0

I have some HTML that I want to "highlight" when I click on it. Pretty straightforward stuff, but i cannot for the life of me get toggleClass to work :/

Here is the HTML:

<div id="mainContent"> <div id="pageTop"> ... </div> <div id="content"> <h2>2 Special Offers</h2> <p>1) Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's.</p> <div id="prod1"> <img src="images/prod1-1.png" width="130" height="109" alt=""> </div> <div id="prod2"> <div id="holdingBox1" class="one"> <p>Choose from over 32 products</p> </div> </div> <div id="prod3"> <div id="holdingBox2" class="two"> <p>Choose from over 32 products</p> </div> </div> </div> <div class="flyout1"> <div id="subProd">Prod 1</div> <div id="subProd">Prod 2</div> <div id="subProd">Prod 3</div> <div id="subProd">Prod 4</div> <div id="subProd">Prod 5</div> <div id="subProd">Prod 6</div> <div id="subProd">Prod 7</div> <div id="subProd">Prod 8</div> </div> <div class="flyout2"> <div id="subProd">Prod 1</div> <div id="subProd">Prod 2</div> <div id="subProd">Prod 3</div> <div id="subProd">Prod 4</div> <div id="subProd">Prod 5</div> <div id="subProd">Prod 6</div> <div id="subProd">Prod 7</div> <div id="subProd">Prod 8</div> </div> <div id="restOfPage"> ... </div> </div> 

and here is the jQuery:

$(document).ready(function() { $('.flyout1').hide(); $("#holdingBox1").on("click",function(){ $(this).toggleClass("hover"); $(".flyout1").slideToggle(); $(".flyout2").hide(); }); $('.flyout2').hide(); $("#holdingBox2").on("click",function(){ $(this).toggleClass("hover"); $(".flyout2").slideToggle(); $(".flyout1").hide(); }); }); 

The slideToggle stuff on my hidden layers works great, adding other functions just seems to break it :/

Here is the CSS "hover" I am trying to apply

.hover { border:1px solid red; } 

Any ideas on how i have monumentally c*cked this up would be greatly appreciated, as I just can't see what I am doing wrong :/

2
  • it's working for me jsfiddle.net/rohitazad/2U3Ww/2 Commented Apr 15, 2013 at 10:39
  • Note that you're hiding .flyout2 on the click of #holdingBox1, but you're not removing the hover class of #holdingBox2 at the same click, so the two can get out of sync. Commented Apr 15, 2013 at 10:40

1 Answer 1

1

I tided up your jquery a little bit: jsfiddle

But it looks like your code is working. Unless there is something that you have not mentioned

Jquery:

$(document).ready(function() { $("#holdingBox1").on("click",function(){ $(this).toggleClass("hover"); $(".flyout1").slideToggle(); $(".flyout2").hide(); }); $("#holdingBox2").on("click",function(){ $(this).toggleClass("hover"); $(".flyout2").slideToggle(); $(".flyout1").hide(); }); }); 

CSS

.hover { border:1px solid red; } .flyout1{display:none;} .flyout2{display:none;} 
Sign up to request clarification or add additional context in comments.

3 Comments

I run it in Chrome, Firefox and IE and it doesn't work, looks like I might have a conflicting CSS somewhere :/ I can't access JSFiddle from behind my companies firewall, well i can i just can't see the output window
you will need to give us more of the code for us to see what is not working
Looks like this some conflicting CSS. I have had to add !important to the .hover class. Cheers guys, least I know I was on the right track, now to code up the bit to eliminate the other conflicts...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.