Forum Moderators: open

Message Too Old, No Replies

setting a property that has only a getter

what does it mean?

         

benihana

2:47 pm on Aug 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I never really touch javascript, but wanted to make a simple way to have a side navigation column toggle on and off, and the content of the page fill the available screen.

Opera has no complaints about the following, but IE complains of 'member not found', and FF - 'setting a property that has only a getter'

the script:


hidden=0;

function shownHide (show, hide){
if (hidden==0){
var fullwidth=document.getElementById(show)
fullwidth.style='margin-left:20px;';
var offscreen=document.getElementById(hide)
offscreen.style='margin-left:-140px; margin-right:-20px;';
hidden=1;
} else {

var fullwidth=document.getElementById(show)
fullwidth.style='';
var offscreen=document.getElementById(hide)
offscreen.style='';
hidden=0;
}
}

is just called with:

<a href="#" onclick="shownHide('content', 'nav')"

pointers much appreciated.
thanks
Ben

garann

12:15 am on Aug 24, 2005 (gmt 0)

10+ Year Member



Getters and setters are methods for accessing the value of a property of an object, to ensure type safety or whatever. Firefox is telling you that you're trying to set a value on what's effectively a read-only property. But I'm not sure what's triggering that in your code...

My suggestion/guess would be to not try and set the

style
of the objects, but set the value of the style property you want to change. For example,
fullwidth.style.marginLeft = '20px';
. And rather than try and set the style to nothing, you can set
marginLeft
to
'auto'
or something innocuous like that.

benihana

8:21 am on Aug 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks v much garann - that fixed it :)