0

In the code of my page there are many href. I want to execute the onclick function for a specific href:

<div style="font-size: 11px; width: 90px;"> text <a href="http://www.domain.com/example" target="_blank"> click here </a></div>

General option:

$('a').on("click", function(variable) {}
eabcde
  • 101
  • 1
  • 7

2 Answers2

1

You need to use Attribute Equals Selector [name=value]

$('a[href="http://www.domain.com/example"]').on("click", function(ev) {
   //click handler for anchor      
});
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0

You will need to add a specific class name or id to the href that you want to bind the action to.

For example:

<a id="this_is_the_one" href="http://www.domain.com/example" target="_blank"> click here </a>

and then your js:

$('#this_is_the_one').on("click", function(variable) {}
Michael
  • 1,247
  • 1
  • 8
  • 18