0

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

2 Answers 2

1

.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

Sign up to request clarification or add additional context in comments.

Comments

1

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.