Change Text on Click

Toggle text back and forth from a selected phrase using this function:

function changeText(idElement) {

    var element = document.getElementById('learn' + idElement);

    if (idElement === 1 || idElement === 2) {

        if (element.innerHTML === 'Learn More') element.innerHTML = 'Close';

        else {

            element.innerHTML = 'Learn More';





<a href="javascript:void();" id="learn1" onclick="javascript:changeText(1)">Learn More</a>

Sourced here.

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.