Adding a hyperlink to text in jQuery

I use innerText to add text to my object. Is there an easy way to add a hyperlink to the text? Trend also has a link attribute.

this.node.innerText = trend.get('value'); 
+6
source share
2 answers

You need to add a DOM element using jQuery wrap ():

$(this).wrap('<a href="..." />') ;

+6
source

Use **WRAP** Feature

  $(someSelector).wrap(function() { var link = $('<a/>'); link.attr('href', 'somewhere_far_far_away'); link.text($(this).text()); return link; }); 
+8
source

Source: https://habr.com/ru/post/951325/


All Articles