code_junkie

How to make a link title the same as its URL using jQuery

Nov 13th, 2011
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. $('a').filter(function() {
  2.  
  3. var title= $(this).attr('href');
  4. return this.hostname && this.hostname !== location.hostname;
  5.  
  6. })
  7. .removeAttr('target')
  8. .attr('rel', 'external')
  9. .attr('title', title);
  10.  
  11. $('a[rel="external"]').click( function() {
  12. window.open( $(this).attr('href') );
  13. return false;
  14. });
  15.  
  16. $('a').each(function() {
  17. var href = $(this).attr('href');
  18. if(this.hostname && this.hostname !== location.hostname) {
  19. $(this).removeAttr('target')
  20. .attr('rel', 'external')
  21. .attr('title', href)
  22. .click(function() {
  23. window.open(href);
  24. return false;
  25. });
  26. }
  27. });
Add Comment
Please, Sign In to add comment