Click to See Complete Forum and Search --> : Tenary operator only validates 1st time


CrazyMerlin
12-28-2005, 03:50 PM
Hey guys!

I'm using tenary operation to set/hide a div when a user clicks an image, but the evaluation, infact the setting of it only happens first time round:

user clicks, div appears
user clicks, div hides
user click, nothing

is this a known problem with the use of the tenary operator on the display property or my declaration


onclick="document.getElementById('divMoney').style.display=(document.getElementById('divMoney').style.display )?'none':'block'"


Thanks

A1ien51
12-28-2005, 04:06 PM
It is not going to work since it will have a value, you need to add a check like:

...display=(document.getElementById('divMoney').style.display =="block")?...

Eric

CrazyMerlin
12-28-2005, 04:35 PM
thx Eric.

I was confused why it works the first time, and then stops working.

Kor
12-29-2005, 04:55 AM
thx Eric.

I was confused why it works the first time, and then stops working.

that's simple. there was there a condition of existence

if(document.getElementById('divMoney').style.display)
that means if the element has a display attribute in style. As it always has, the value 'none' was always taken...