I have code which is trivial but only works in IE not Firefox.
$(document).ready(function(){
$('li#first').click();
});
I have also tried:
document.getElementById('first').click();
But that doesn't work either.
Is this an IE bug/feature or is click()
not supported in the other browsers?
Responding to comments:
- There is a single element with ID first, no more.
- It is an onclick on the list element that expands the element and moves focus on a Google Map element.
- Running the code in patrick's response (adding another click event to the element) produced some interesting behaviour. When running
$('li#first').click()
only the new event fired, but physically clicking the element with the mouse fired both (new and original).
Thanks in advance.
Firefox does not support click().
Running
document.getElementById('first').click()
returns the following errorclick is not a function
So I added a snippet of code to add click() functionality to every element. This code was found after a painful series of google searches resulting in this thread.
The snippet is below and needs to be included just once on the page:
try this html
js
also if this is somethng you don't want to do theb also try something like this:
Your code should work in Firefox. Here's a full snippet that proves it:
Firefox does support the .click() JQuery function. I had the same problem, until I specified the tag name in my selector. Essentially, I had something like this:
Which didn't work. I had to change the javascript to this:
Are you trying to go to the first link? You can't trigger a link's default action via a click.
But here's a workaround:
Source: http://forum.jquery.com/topic/jquery-a-0-click-not-working