views:

20

answers:

2

I want to change the behaviour on a "a href" link but only on ones that have a custom made attribute called open

e.g.

<a href="#" action="open">Link 1</a>
<a href="http://www.google.co.uk/"&gt;&lt;/a&gt;

I want to change only the behaviour of the first one. So I do a:

jQuery('a[action|=open]').live('click', function(evt) {
      do something;
});

but nothing happens. The selector selects all the specified elements but the click event is not exectued. What am I doing wrong?

+2  A: 

It's easier to do this with a class name:

$('a.open').click(function(){...})

<a href="#" class="open">Link 1</a>
Diodeus
+1, more compatible cross-browser, and keeps the markup valid against the spec
Ross
I agree, although I think ip's code should work, it does in my tests.
Adam
Strange, because it doesn't work if I am not using a class. What browser did u tested on Adam?
ip
A: 

Your code will work, but not all browsers support custom attributes. I suggest following @Diodeus' answer, and using classes. This jsFiddle works for me in Chrome, but it may not in all browsers.

Rocket