Javascript Tip Of The Day: “When Is A Width Not A Width?”

This is a bit of a gotcha for young players in the Javascript game. You have a web page with a DIV which you fill dynamically with, let’s say, 5 IMG elements. How do you get the width of the DIV? You can try “document.getElementById(‘divId’).width” but it will do you no good. The answer: use “document.getElementById(‘divId’).offsetWidth”. Here’s a handy guide when it comes to DHTML element position and locations.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: