2013-08-08 13 views
5

Sto usando innerText per aggiungere testo al mio oggetto. C'è un modo semplice per aggiungere un collegamento ipertestuale al testo? 'trend' ha anche un attributo chiamato 'link'.Aggiunta di collegamento ipertestuale al testo in JQuery

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

Non puoi usare invece innerHTML? http://www.w3schools.com/jsref/prop_html_innerhtml.asp – Henrik

risposta

5

È necessario aggiungere un elemento DOM usando involucro di jQuery():

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

7

Usa **WRAP** funzione

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