You can use .html()
Try:
var href = 'https://buildinfopage.local/app+' + (buildInformation.earVersion.substring(0, buildInformation.earVersion.indexOf('-')));
$("#releaseNotes").html(('<a href="'+href+'">'+href+'</a>'));
Pergunta
So I'm seriously deficient in the Javascript department. I'm writing text to a div by but I'd like this to be a link. The text displays correctly, I'd just like to 'wrap' with a href tags?
** HTML Markup **
<tr>
<td>Release Notes</td>
<td colspan="3"><span style="color: blue;" id="releaseNotes"></span></td>
</tr>
** Part of a function **
$("#releaseNotes").text(('https://buildinfopage.local/app+' + (buildInformation.earVersion.substring(0, buildInformation.earVersion.indexOf('-')))));
Solução
You can use .html()
Try:
var href = 'https://buildinfopage.local/app+' + (buildInformation.earVersion.substring(0, buildInformation.earVersion.indexOf('-')));
$("#releaseNotes").html(('<a href="'+href+'">'+href+'</a>'));
Outras dicas
If your div
already contains some inner elements, then you would append
an a
element to it:
var href, link;
href = 'https://buildinfopage.local/app+' + buildInformation.earVersion.substring(0, buildInformation.earVersion.indexOf('-'));
link = $("<a href='" + href + "'>" + href + "</a>");
$("#releaseNotes").append(link);
$("#releaseNotes").html("<a href='https://buildinfopage.local/app+" + (buildInformation.earVersion.substring(0, buildInformation.earVersion.indexOf('-'))) + "'>Build info</a>");
The .html()
method will let you replace arbitrary html to your element
var href = 'https://buildinfopage.local/app+' + (buildInformation.earVersion.substring(0, buildInformation.earVersion.indexOf('-')));
$("#releaseNotes").html('<a href="' + href + '" >' + href + '</a>');
Just need to wrap the text in a link tag. I extracted the href as a variable as we are usingit both as a link and as text
In span tag, there is no text attribute, so in javascript you can use .html attribute.
$("#releaseNotes").html(('https://buildinfopage.local/app+' + (buildInformation.earVersion.substring(0, buildInformation.earVersion.indexOf('-')))));