Last Updated: October 11, 2021
·
1.98K
· idered

[JS] Not well known link() method

Probably every jQuery developer know how to create link with it:

$('<a href="http://google.com"/>').text('Google');

or:

$('<a href="http://google.com">Google</a>');

But there's also a little know link() method:

'Google'.link('http://google.com');

3 Responses
Add your response

Interesting find! Is there a spec for the function somewhere? I wonder what's the browser support...

over 1 year ago ·

Wow!

W3Schools says it's supported in "All Major Browsers". A quick test in Firefox, IE7, and Chrome shows it works in all of those.

I never expected a method like that on the String object. It's very Pythonic...

over 1 year ago ·

There are many other HTML wrapper methods in JS besides just link() too.

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String#HTML_wrapper_methods

over 1 year ago ·