0

I have tried a few different approaches to updating the text colour of a button with javascript but none have worked:

document.getElementById(elementID).textContent.fontcolor = "red";
document.getElementById(elementID).textContent.fontcolorstyle = "red";
 document.getElementById(elementID).textContent.style = "red";

So my question is how do you access the text of a button and change the colour with JS?

3 Answers 3

2

You can do this by changing the color styling of the button as follows:

document.getElementById('btn').style.color='red';
<button id="btn">Click</button>

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

Comments

1

You can do:

document.getElementById('btn-id').style.color = 'red'

Comments

1

you can use the following:

<button id="submit" onclick="textChange()">Click me</button>

function textChange(){
    let btn = document.getElementById("submit");
    btn.style.color = "red";
}

thanks.

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.