Forum Moderators: open

Message Too Old, No Replies

multiclicks for OnClick to work

Takes several clicks on a dive before the onclik works

         

jerryb

7:31 pm on Nov 29, 2004 (gmt 0)

10+ Year Member



Why do I have to click this div several times before the onClick works when if I place an image in there - one click does the job.

<div onClick="function(arg)">Word</div>

Bernard Marx

7:44 pm on Nov 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



function might know the answer to that one.

jerryb

2:04 am on Nov 30, 2004 (gmt 0)

10+ Year Member



the function is (from my earlier post)

function chgdsplay(me)
{
if (me.style.display=="none"){
me.style.display="block";}
else {
me.style.display="none";}
}

Which is what I assume you where angling for.

Bernard Marx

1:51 pm on Nov 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Properties set via stylesheet can't be read directly off the element's local style object.
Here's what happens:

1. 1st click: The display property is an emty string .
- test fails, and property set (locally this time) to 'none'.

2. 2nd click: Now we're in business.

Here's a solution:

function togDisplay(id)
{
var style = document.getElementById(id).style;
style.display =!style.display? 'block' : '';
}

This assumes that
a) The default style in the stylesheet is 'none';
b) Any elements that are shown from the start have 'display:block;' in their own inline style attribute (but will default to the stylesheet's 'none' whenever this is removed).

jerryb

10:07 pm on Nov 30, 2004 (gmt 0)

10+ Year Member



And Thanks for the pointer and suggestions