Luca
Luca

Reputation: 1

How should I write the width of the body of my document as a condition in JavaScript?

I'm working on a side navigator menu for a website and obviously I want to make it responsive and it has two different aspects on a large screen as a desktop and on a tighter screen as on a mobile phone. The problem is that I don't know how to write correctly the width of the body of my HTML document as a condition in JavaScript. That's what I tried but it simply doesn't work, so I thought it could be a syntax error by me.

function openMenu() {
   if (document.body.width >= 415) {
      // code to run
   } else if (document.body.width <= 414) {
      // code to run
   }
}

Upvotes: 0

Views: 25

Answers (0)

Related Questions