-1

Okay, I'm pretty new to the JavaScript stuff, and I would like some help.

The variable that needs to be auto-refreshed:

var width = document.body.clientWidth;

So basically, I want to do different stuff depending on the width of the document. But how do I auto-update the value of width? Please JavaScript only, since I don't really get jQuery yet.

Thanks in advance! :)

  • That is a common problem people face. Usually it is best to go about solving your problem in a way which does not require monitoring the clientWidth. – Travis J Apr 17 '13 at 16:35
  • 1
    Can be answered by http://stackoverflow.com/questions/641857/javascript-window-resize-event – robbrit Apr 17 '13 at 16:36
  • 1
    Resize will not handle if content makes the width larger. – Travis J Apr 17 '13 at 16:36

1 Answers1

-1

JavaScript is event-based so any code that gets executed is the result of an event. There are many events such as mousemove or click.

You need to figure out which events you want to listen to. Probably something related to the width of the body changing, like more data being loaded, or some animation.

Halcyon
  • 54,624
  • 10
  • 83
  • 122