Solved

Swap DIV's using jQuery?

Posted on 2013-01-03
3
295 Views
Last Modified: 2013-01-03
Hi all and happy new year!

I am trying to change the behaviour of an element on my page when the screen is resized.

I have a left navigation menu that is open at max screen width of say 1200px but when the window is resized below 1200px I would like the left navigation to be closed and only open when hovered (like Amazons menu).

I have both elements setup and ready to go. For the normal navigation I have  a css class of ".dropdown open" and for the closed hover menu I have a css class of ".dropdown"

Is there a way to use jQuery to swap the classes when the window is resized?

I'd appreciate some advice on how to do this please....
0
Comment
Question by:rafique12
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
Kyle Hamilton earned 500 total points
Comment Utility
$(window).resize( function () {

var w = $(window).width();

if (w < 1200) {
   $(".dropdown").removeClass("open");
}else{
   $(".dropdown").addClass("open");
}
});

Open in new window

0
 

Author Closing Comment

by:rafique12
Comment Utility
Thankyou so much. Works perfect!!!
0
 
LVL 25

Expert Comment

by:Kyle Hamilton
Comment Utility
:)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now