Reputation: 919
I'm trying to add an <a>
element around a string that currently exists as a Javascript variable.
The resulting element should display as: 'copyright symbol' + 'companyName' + 'this year's date'. BUT with ONLY the variable 'companyName' acting as an html link
Existing JS
const companyName = "ANY BUSINESS NAME";
function setCopyrightText() {
$("#ifcCopyright").html("© " + companyName + " " + new Date().getFullYear());
}
Existing HTML
<span class="textHeavy fontWhite" id="ifcCopyright"></span>
I've tried several approaches and I'm beginning to realise there must be a simpler solution but I'm missing it _ I've been through several answers on Stack but unsuccessful in finding what I need
Thanks in advance for any suggestions
Upvotes: 0
Views: 40
Reputation: 2752
Please put link to your company site where the #
is currently placed.
const companyName = "Peuconomia Int'l Pvt. Ltd.";
function setCopyrightText() {
$("#ifcCopyright").html("© <a href=\"#\">" + companyName + "</a> " + new Date().getFullYear().toString());
}
setCopyrightText();
Upvotes: 1
Reputation: 20651
.html() takes A string of HTML to set as the content of each matched element. Did you try this :
const companyName = "ANY BUSINESS NAME";
function setCopyrightText() {
$("#ifcCopyright").html("© <a href='https://www.google.com' target='_blank'>" + companyName + "</a>" + new Date().getFullYear());
}
setCopyrightText();
Upvotes: 1