Posted By

sb_01 on 10/01/10


Tagged

javascript jquery


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

hmvrulz


Open Link in new Window


 / Published in: jQuery
 

  1. $('a[rel*=external]').click( function() {
  2. window.open(this.href);
  3. return false;
  4. });
  5.  
  6. // Better Solution
  7. // thanks to: emelendez
  8. $('body').delegate('a[rel=external]', 'click', function(){
  9. window.open(this.href);
  10. return false;
  11. })

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: emelendez on October 2, 2010

if you have lots of "a" tags (normal) in your page (imagine 100 anchors) then it binds "n" times to each one.

In that case it is better to delegate (once) to a parent (body, in general):

$('body').delegate('a[rel=external]', 'click', function(){ window.open(this.href);return false;})

You need to login to post a comment.