Solved

Swap DIV's using jQuery?

Posted on 2013-01-03
3
307 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
Kyle Hamilton earned 500 total points
ID: 38740174
$(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
ID: 38740389
Thankyou so much. Works perfect!!!
0
 
LVL 25

Expert Comment

by:Kyle Hamilton
ID: 38740447
:)
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

728 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