michaelmcgurk michaelmcgurk -4 years ago 100
HTML Question

Change value of hyperlink text using jQuery

I have the following HTML:

<span id="callnow" class="mhMobile callnow"><a href="tel:01234567890">01234567890</a></span>


Is it possible when the page loads, I can change the value of the hypertext label to read
Call Now
?

I tried with this Javascript but no luck so far:

(function(text){
setTimeout(function(){
document.getElementById("callnow a").innerHTML = "Call Now";
}, 1000);
})(text)


DEMO:
https://jsfiddle.net/7obax3ta/

Many thanks for any help :)

Answer Source

As stated in other answers document.getElementById() won't accept css3 selector tryquerySelector.Also remove the unwanted parameters

A sample demo

(function(){
    setTimeout(function(){
        document.querySelector(".callnow a").innerHTML = "Call Now";
    }, 1000);
})()
<span id="callnow" class="mhMobile callnow"><a href="tel:01234567890">01234567890</a></span>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download