inputforcolor
inputforcolor

Reputation: 919

Adding <a> element to an existing Javascript variable for use in .html statement

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("&copy; " + 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

Answers (2)

Ariel
Ariel

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("&copy; <a href=\"#\">" + companyName + "</a> " + new Date().getFullYear().toString());
}

setCopyrightText();

Upvotes: 1

Tushar Shahi
Tushar Shahi

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("&copy; <a href='https://www.google.com' target='_blank'>" + companyName + "</a>" + new Date().getFullYear());
} 

setCopyrightText();

Codepen

Upvotes: 1

Related Questions