Adding Hyperlink to text in JQuery
Asked Answered
L

2

15

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');
Lanham answered 8/8, 2013 at 14:20 Comment(1)
Can't you just use innerHTML instead? w3schools.com/jsref/prop_html_innerhtml.aspCelestaceleste
C
15

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

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

Caines answered 8/8, 2013 at 14:23 Comment(0)
P
16

Use **WRAP** function

  $(someSelector).wrap(function() {
       var link = $('<a/>');
       link.attr('href', 'somewhere_far_far_away');
       link.text($(this).text());
       return link;
    });
Pimple answered 8/8, 2013 at 14:23 Comment(0)
C
15

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

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

Caines answered 8/8, 2013 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.