Adding Hyperlink to text in JQuery

Parag Srivastava picture Parag Srivastava · Aug 8, 2013 · Viewed 26.2k times · Source

I am using innerText to add text to my object. Is there an easy way to add a hyperlink to the text? 'trend' also has a attribute called 'link'.

this.node.innerText = trend.get('value');

Answer

Vaibs_Cool picture Vaibs_Cool · Aug 8, 2013

Use **WRAP** function

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