Forum Moderators: open

Message Too Old, No Replies

Simulated click on div

how to simulate a click on a div to force focus

         

dazedandconfused

1:20 pm on Aug 15, 2006 (gmt 0)

10+ Year Member



Hi,

I have four overlapping gifs as a background that move around when the user clicks various links. These each have a unique z-index (1, 2, 3, 4).

I have a content box that has its visibility set to hidden and its z-index set to 50.

I've written the js to change the visibility property of the div using but when it appears on the screen it is beneath the background gifs, even though the z-index is higher.

When I click on the div it gets focus and 'comes to the front' so that it looks as it should.

I've tried to simulate a user click on the div with .click() but i get the following error:

document.getElementById("holder").click is not a function

This problem only comes up in Safari (v2.0.3) - Firefox (pc & mac), Camino, even IE (pc) display it properly and I'm at a loss regarding next steps.

Any help/suggestions at all would be greatly appreciated.

Gy

Rambo Tribble

10:35 pm on Aug 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The method to apply focus is, oddly enough, focus(). A div in not an element that normally accepts focus, however. To superimpose your div over an image give it a position:absolute value, if it is in the same container as the image.

supermoi

1:13 am on Aug 18, 2006 (gmt 0)

10+ Year Member



Well you can set a function to the click, onclick or onmousedown event, but the user will still have to click on your objet for the function to be called. However, you say you have a function that makes the div comes on top when a user clicks on it, so I believe you have done that already. What you'd have to do, if I understood you correctly, is just to call this function when the page loads.
It sounds like a too easy solution though, so I'm not sure I actually understood exactly what you meant.

dazedandconfused

3:31 pm on Aug 18, 2006 (gmt 0)

10+ Year Member



RE Rambo Tribble : I know focus() is the method to apply focus to an element... pretty obvious stuff. But as you correctly pointed out focus() won't work on a div. Neither will click() to simulate a user event.

The div has position:absolute and a z-index higher than the images that are also position:absolute.

The div has its visble property set to hidden with css, then when a link is clicked, a method to switch the visible property to visible.

The problem I am having is when the property is switched to visible, the z-index seems to become irrelevant until i physcially click on the div, which redeems things.

So is there anyway to assign focus or simulate a click on a div? I've only been using the language for a week, my background is in actionscript/php and I'm not used to having to work around different browsers inability to render the same code in the same way...

why - o - why doesn't everyone use firefox? what reason do people have for using anything else?

Rambo Tribble

1:49 am on Aug 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Z-index is irrelevant to absolutely positioned items; they always go on top of preceding elements within the same positioned container.

[edited by: Rambo_Tribble at 1:51 am (utc) on Aug. 19, 2006]

dazedandconfused

3:22 pm on Aug 21, 2006 (gmt 0)

10+ Year Member



z-index is NOT irrelevant to absolutley positioned divs. suprisingly enough it determines the stacking order between the divs... funny that

Rambo Tribble

3:48 am on Aug 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, amazingly enough, it only applies to positioned elements (since z-index only applies to them) within the same stacking context.

Rambo Tribble

2:39 pm on Aug 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have been unable to duplicate the problem based on my interpretation of your description. If you could post a minimal example, we might get further.