1

I want to use js to change the background color that is set to white in the css. Not sure why nothing is happening.

.html
<body>
  <div class="invoice-box">
    <table cellpadding="0" cellspacing="0">
      <tr class="top">
        <td colspan="2">
          <table>
            <tr>
              <td class="title">
                <img src="emoji.png" width="100">
              </td>
.css
.invoice-box {
  background: white;
  max-width:800px;
  margin:auto;
  padding:30px;
  border:1px solid #eee;
  box-shadow:0 0 10px rgba(0, 0, 0, .15);
  font-size:16px;
  line-height:24px;
  font-family:'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;
    color:#555;
.js
document.getElementById("invoice-box").style.background = "red";

4 Answers 4

1

If you can use jquery just do as sample

$('#element').css('background-color', '#ffffff') 

Note: #ffffff = white color

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

Comments

0

You have used getElementById which fetches html elements from Id, but you have defined invoice-box as class. Define it to id as well

<body>
<div class="invoice-box" id="invoice-box">
    <table cellpadding="0" cellspacing="0">
        <tr class="top">
            <td colspan="2">
                <table>
                    <tr>
                        <td class="title">
                            <img src="emoji.png" width="100">
                        </td>

Comments

0
document.querySelector(".invoice-box").style.background = "red";

How about using querySelector?

Comments

0

you are using class and calling id in the javascript, use instead of class

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.