Beverly Lodge
Beverly Lodge

Reputation: 98

How to add class if browser window is bigger than 768

This has just been driving me bonkers. I've looked this up in several places and can't get it to work. All I want to do is add a "fancybox-iframe" class in a menu item (the last one, "contact us") as shown here, and so far, I can't get any code to work. I cannot do this in CSS, either. Can someone please help!!!??

Upvotes: 0

Views: 720

Answers (2)

Beverly Lodge
Beverly Lodge

Reputation: 98

I got it! Was missing a bit of love - I was being to literal, thanks Josh!

    <script>
    jQuery(document).ready(function($) {
        if (window.innerWidth > 768) {
        document.getElementById('menu-item-34').className +='fancybox-iframe';
       }
     });
    </script>

Upvotes: 0

Josh
Josh

Reputation: 332

Could you do something like this?

if (window.innerWidth > 768) {
    document.getElementById('menu-item-34').className += ' fancybox-iframe';
}

(where menu-item-34 is the id of the contact us button)

Upvotes: 2

Related Questions