Interesting, this is probably a "feature request" (ie bug) for jQuery. The jQuery click event only triggers the click action (called onClick event on the DOM) on the element if you bind a jQuery event to the element. You should go to jQuery mailing lists ( docs.jquery.com/Discussion ) and report this.
This might be the wanted behavior, but I don't think so EDIT: I did some testing and what you said is wrong, even if you bind a function to an 'a' tag it still doesn't take you to the website specified by the href attribute. Try the following code: html> aaa Also notice that even if you bind the click event to the link it still doesn't go purple once you click the button. It only goes purple if you click the link directly I did some research and it seems that the .
Click is not suppose to work with 'a' tags because the browser does not suport "fake clicking" with javascript. I mean, you can't "click" an element with javascript. With 'a' tags you can trigger its onClick event but the link won't change colors (to the visited link color, the default is purple in most browsers).
So it wouldn't make sense to make the $(). Click event work with 'a' tags since the act of going to the href attribute is not a part of the onClick event, but hardcoded in the browser.
Interesting, this is probably a "feature request" (ie bug) for jQuery. The jQuery click event only triggers the click action (called onClick event on the DOM) on the element if you bind a jQuery event to the element. You should go to jQuery mailing lists ( docs.jquery.com/Discussion ) and report this.
This might be the wanted behavior, but I don't think so. EDIT: I did some testing and what you said is wrong, even if you bind a function to an 'a' tag it still doesn't take you to the website specified by the href attribute. Try the following code: aaa it never goes to google.Com unless you directly click on the link (with or without the commented code).
Also notice that even if you bind the click event to the link it still doesn't go purple once you click the button. It only goes purple if you click the link directly. I did some research and it seems that the .
Click is not suppose to work with 'a' tags because the browser does not suport "fake clicking" with javascript. I mean, you can't "click" an element with javascript. With 'a' tags you can trigger its onClick event but the link won't change colors (to the visited link color, the default is purple in most browsers).
So it wouldn't make sense to make the $(). Click event work with 'a' tags since the act of going to the href attribute is not a part of the onClick event, but hardcoded in the browser.
I tried your code, and it does exactly as you said it does, but my code does as I described above. I'll do some more experiments and see if I can put together a simple example of my results that you can try. – Mnebuerquo Nov 8 '09 at 3:16 Ok.It must have been something I did wrong.
I was absolutely certain at the time I posted my question that it was working, but since I tried your example mine no longer works. I'll just go back to using window. Location to change the page and not try faking the click.
– Mnebuerquo Nov 8 '09 at 18:47.
If you look at the code for the $. Click function I'll bet there is a conditional statement that checks to see if the element has listeners registered for theclick event before it proceeds. Why not just get the href attribute from the link and manually change the page location?Window.location.
Href = $('a'). Attr('href'); EDIT: Here is why it doesn't click through, from the trigger function, jQuery source for version 1.3.2: // Handle triggering native . Onfoo handlers (and on links since we don't call .click() for links) if ( (!elemtype || (jQuery.
NodeName(elem, 'a') && type == "click")) && elem"on"+type && elem"on"+type. Apply( elem, data ) === false ) event. Result = false; // Trigger the native events (except for clicks on links) if (!bubbling && elemtype &&!event.
IsDefaultPrevented() &&!(jQuery. NodeName(elem, 'a') && type == "click") ) { this. Triggered = true; try { elem type (); // prevent IE from throwing an error for some hidden elements } catch (e) {} } After it calls handlers (if there are any) jQuery triggers an event on the object.
However it only calls native handlers for click events if the element is not a link. I guess this was done purposefully for some reason. This should be true though whether an event handler is defined or not, so I'm not sure why in your case attaching an event handler caused the native onClick handler to be called.
You'll have to do what I did and step through the execution to see where it is being called.
I can certainly use window. Location and the href as I mentioned in the question. I'm trying to understand what happens in jquery click(), and what causes the results I observed.
– Mnebuerquo Nov 8 '09 at 3:18 I edited my answer to show where in jQuery source it deals with $.click() calls on links. – Ryan Lynch Nov 8 '09 at 5:48 window. Location works, but not not post HTTP Referrer, and breaks the back button.
– Chase Seibert Apr 9 '10 at 15:40.
It does nothing because no events have been bound to the event. If I recall correctly, jQuery maintains its own list of event handlers that are bound to NodeLists for performance and other purposes.
Click handlers on anchor tags are a special case in jQuery. I think you might be getting confused between the anchor's onclick event (known by the browser) and the click event of the jQuery object which wraps the DOM's notion of the anchor tag. You can download the jQuery 1.3.2 source here.
The relevant sections of the source are lines 2643-2645 (I have split this out to multiple lines to make it easier to comprehend): // Handle triggering native . Onfoo handlers (and on links since we don't call .click() for links) if ( (!elemtype || (jQuery. NodeName(elem, 'a') && type == "click")) && elem"on"+type && elem"on"+type.
Apply( elem, data ) === false ) event. Result = false.
I edited my answer not noticing that you had answered with some similar info. Oops. – Ryan Lynch Nov 8 '09 at 16:53.
I have a timer in my javascript which needs to emulate clicking a link to go to another page once the time elapses. To do this I'm using jquery's click() function. I have used $().trigger() and window.
Location also, and I can make it work as intended with all three. I've observed some weird behavior with click() and I'm trying to understand what happens and why. I'm using Firefox for everything I describe in this question, but I am also interested in what other browsers will do with this.
If I have not used $('a'). Bind('click',fn) or $('a'). Click(fn) to set an event handler, then calling $('a').click() seems to do nothing at all.
It does not call the browser's default handler for this event, as the browser does not load the new page. However, if I set an event handler first, then it works as expected, even if the event handler does nothing. This loads the new page as if I had clicked the a myself.
So my question is twofold: Is this weird behavior because I'm doing something wrong somewhere? And Why does calling click() do nothing with the default behavior if I haven't created a handler of my own? As Hoffman determined when he tried to duplicate my results, the outcome I described above doesn't actually happen.
I'm not sure what caused the events I observed yesterday, but I'm certain today that it was not what I described in the question. So the answer is that you can't "fake" clicks in the browser and that all jquery does is call your event handler. You can still use window.
Location to change page, and that works fine for me.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.