Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using JQuery to get string value of an onclick() event

Wondered if there was good way to do this, thought I would post to the SO community...

There is a 3rd party web page that I have no control over how it renders, but they allow me to add JQuery.

Using the JQuery, I am creating a nav menu on the side of the page, it will be a list of links. The onclick event of these links I get from existing onclick events already on the page, but when I do a:

var linkLoc = $('#theLink').attr("onclick");

linkLoc returns:

function onclick(event) {
  handleJumpTo("com.webridge.entity.Entity[OID[E471CB74A9857542804C7AC56B1F41FB]]", "smartform");
}

instead of what I would expect:

handleJumpTo("com.webridge.entity.Entity[OID[E471CB74A9857542804C7AC56B1F41FB]]", smartform");

I think JQuery is trying to get the event for binding, but I need the actual Javascript markup since I'm creating the HTML dynamically. I guess I could substring the "function onclick(event) {" out, but seems kind of hacky.

Any ideas of an elegant way I could get the onclick markup?

like image 405
Mark Kadlec Avatar asked Mar 24 '11 16:03

Mark Kadlec


1 Answers

$("#theLink") would return a jQuery object whereas $("#theLink")[0] would give a DOM object. This is a resson that $("#thelink")[0].getAttributeNode('onclick').value would work.

like image 58
user2994381 Avatar answered Sep 28 '22 09:09

user2994381