1
document.getElementById("usersList").innerHTML.style="background-color:red" += "<th>" + newuser + "</th>";

With this syntax I am not able to get the background-color of my table rows.

Could you please give me the valid syntax to my question?

2

3 Answers 3

1

These are two different statements, also style is not a prpoerty on .innerHTML but on the element itself.

Also it is not a great idea to overwrite the complete style attribute, instead set the specific properties.

document.getElementById("usersList").style.backgroundColor="red";    
document.getElementById("usersList").innerHTML += "<th>" + newuser + "</th>";
Sign up to request clarification or add additional context in comments.

Comments

0

This is a way to add style

document.getElementById("usersList").style.backgroundColor = "red";

Comments

0

You are missing these two points:

  • backgroundColor is applied to the style property of the element
  • innerHTML is used to add HTML content in the element.

var newuser = 'someUser';
document.getElementById("usersList").style.backgroundColor="red";    
document.getElementById("usersList").innerHTML += "<th>" + newuser + "</th>";
<table id='usersList' border='1'></table>

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.