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


My goal is to create the title of each external link equal to my href attribute.

My question is, how can I make the title variable for the attr function?

  $ ('a'). Filter (function () (title = $ (this) .attr ('href'); return.hostname and this.hostname! == location.hostname;}) .removeAttr ('target') .attr ( 'Rel', 'external') .attr ('title', title); $ ('A [rel = "external"]). Click (function () {window.open ($ (this) .attr ('href')); return false;});  

I think I somehow have it backwards, and the answer is

  $ ('a'). Each (function () {var href = $ (this) .attr ('href'); if (this.hostname & this.hostname! == location .hostname) {$ (this) .removeAttr ('target' ) .attr ('rel', 'external') .attr ('title', href). (Function () {window.open (href); back untrue;});}});  

Comments