Satch3000
Satch3000

Reputation: 49422

JQuery add event to anchor and get url

I am trying to get the childBrowser plugin to work on links by adding the code at runtime to links.

Normally, if I was adding to code manually to the links, this is how it would look:

<a href="#" window.plugins.childBrowser.showWebPage('http://www.google.com');>click me</a>

Now, because I need to do it at runtime I've got this together:

$('a').on('click', function () {

    window.plugins.childBrowser.showWebPage('http://www.google.com');

});

But the problem is that all links might have a different url so I need to somehow use the code about but with the link that it comes with and not a hardcoded url as above.

Links would initially look like below.

<a href="http://www.somelink.com">click me</a>

How could I do this?

Upvotes: 0

Views: 138

Answers (2)

codingbiz
codingbiz

Reputation: 26396

Try this

$('a').on('click', function () {

    window.plugins.childBrowser.showWebPage($(this).attr('href'));

});

Upvotes: 0

Anoop
Anoop

Reputation: 23208

Use this.href

$('a').on('click', function () {

    window.plugins.childBrowser.showWebPage(this.href);
    return false; 

});

Upvotes: 3

Related Questions