Jump to content
Sign in to follow this  
fee

Can i check height?

Recommended Posts

I was trying this:

if (document.getElementById('name').height > 23) {// do something}

but i got: 'setting a property that has only a getter' error message.How can I check it?

Share this post


Link to post
Share on other sites

That probably means that the compiler thinks you're trying to set the height.Try this?

x=document.getElementByID("name")y=x.heightif(y>23) {//do something}

Share this post


Link to post
Share on other sites

I have a few additions to this.First of all, you don't need the variable x.You could just do this:

y=document.getElementByID("name").heightif(y>23){//do something}

But even so, you might mave an other problem. The y variable may not contain the objects height value as an integer, but rather a string with "px" added to it (like "200px", for example).If you get that problem, you can fix it like this:

x=y.slice(0,y.length-2);

This will shave the last two characters off the string, and ad the rest to the variable x (like "200", for example).Even so, you might still get the problem that x is treated as a string, and not an integer. If you get that, you can fix it like this:

x=eval( y.slice(0,y.length-2) );

What eval() does is execute a string as code, so if the value of y.slice(0,y.length-2) is the string "200", it will output 200, like you had written it into the code by hand.Good luck with it!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...