JavaScript: Invoking click-event of an anchor tag from javascript?

If you have jquery installed then why not just do this: $('#proxyAnchor').click() As to why your original code is not working - it is probably because you are calling 'onclick', and not 'onclick()'. Without the parenthesis javascript will return whatever is assigned to the onclick property, not try to execute it Try the following simple example to see what I mean: var f = function() { return " alert(f()) The first will display the actual text of the function, while the second will display the word ".

If you have jquery installed then why not just do this: $('#proxyAnchor').click(); As to why your original code is not working - it is probably because you are calling 'onclick', and not 'onclick()'. Without the parenthesis javascript will return whatever is assigned to the onclick property, not try to execute it. Try the following simple example to see what I mean: var f = function() { return " alert(f()); The first will display the actual text of the function, while the second will display the word ".

– samjudson Jun 11 '09 at 13:30 1 Thanks Samjudson. IT worked – Shyju Jun 11 '09 at 13:30.

You should call click event like that : document. GetElementById("proxyAnchor").click(); // $('#proxyAnchor').click(); but in your case you should set window's location to redirect page, if you want that.

I believe you want to invoke the click event. Not the "onClick. " Also, be sure to include the parenthesis () when you're invoking a method.

Don't confuse methods (which end with ( and )) with attributes and properties which do not end with ( and ). // Using jQuery - Which you tagged... $("#proxyAnchor"). Attr("href", proxyImgSrc).click().

Yes. Click event – Shyju Jun 11 '09 at 12:09.

I believe this is what you're after: var proxyImgSrc="CostMetrics. Aspx? Model=" + model +"&KeepThis=true&TB_iframe=true&height=410&width=650"; $("#proxyAnchor").

Attr('href', proxyImgSrc). Trigger("click").

For an immediate page change, you can also do this: var proxyImgSrc= "CostMetrics. Aspx? Model=" + model + "&KeepThis=true&TB_iframe=true&height=410&width=650"; window.

Location = proxyImgSrc; Here's an example from W3 Schools: w3schools.com/js/tryit.asp?filename=tryj....

I have a page with an anchor tag. In my JavaScript I am setting the HREF attribute of the anchor tag dynamically based on some if-else conditions. Now I want to invoke the click event of the anchor tag programmatically.

I used the below code, but was not successful. Can any one tell me how to go ahead?

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.

Related Questions