Jump to content

Can i check height?


fee

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?

Link to comment
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}

Link to comment
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!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...