jQuery Selector How to - Select anchor link by attribute value








Question

We would like to know how to select anchor link by attribute value.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.4.2.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from  ww  w. j a v a2  s.c  o  m-->
    $('a[action|=open]').live('click', function(evt) {
        console.log('test');
    });
});
</script>
</head>
<body>
  <a href="#" action="open">Link 1</a>
  <a href="">no action</a>
</body>
</html>

The code above is rendered as follows: