Javascript: get element's current “onclick” contents?

Assuming your anchor tag is well-formed, you can get the literal text of that attribute using getAttribute(), e.g.

Assuming your anchor tag is well-formed, you can get the literal text of that attribute using getAttribute(), e.g. : alert(document. GetElementById('test'). GetAttribute('onclick')); Hopefully you aren't using onclick for some unscrupulous purpose like storing data.

:3.

Thanks, this worked. My purposes are lacking only in a few scruples - I'm making a GM script to automate clicks on a site that tries to avoid automating clicks by making links call randomly-generated onclick functions first. This way, I can simply grab the function name, eval() it, and then document.

Location to the href. :) – Mala Jul 15 '10 at 8:38 Maybe I shouldn't have asked about scruples, heh. The first thing that comes to mind on reading your description is conning advertising click-throughs, but I doubt you'd use a GM script if you were serious about that.

:3 I'll just continue to assume the best... – Faisal Jul 15 '10 at 9:17 nothing illegal/immoral. Just some annoying "click here to remove this box" crap – Mala Jul 15 '10 at 9:30 Ah, good fun. :3 – Faisal Jul 15 '10 at 10:34 @All - doesn't works on IE8 :( – Varun 8 May8 at 8:40.

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