Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7432501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:28:03+00:00 2026-05-29T09:28:03+00:00

Trying to create a simple document that gets the parentNode then applies a background

  • 0

Trying to create a simple document that gets the parentNode then applies a background color. My getElementByTagName is “p” so the parentNode would be the <body>. The background color should then be applied to the entire document, right? I’m getting an “object expected” error.

<!--purpose is to use parent node and change the background color-->
<html>
<body>
<head>
<script type="text/javascript" language="javascript">
function changeIt() {
  var node;
  node = document.getElementsByTagName("p").parentNode;
  node.style.background-color = '#0033dd';
}
</script>
</head>

<div id="teams">
  <h1>NFL Teams</h1>

  <h2>NFC North</h2>
  <p>Chicago Bears</p>
  <p>Green Bay Packers</p>
  <p>Minnesota Vikings</p>
  <p>Detroit Lions</p>

  <h2>NFC South</h2>
  <p>New Orleans Saints</p>
  <p>Atlanta Falcons</p>
  <p>Carolina Panthers</p>
  <p>Tampa Bay Buccannears</p>

  <h2>NFC East</h2>
  <p>Dallas Cowboys</p>
  <p>Washington Redskins</p>
  <p>Philadelphia Eagles</p>
  <p>NY Giants</p>

  <h2>NFC West</h2>
  <p>San Francisco 49ers</p>
  <p>Arizona Cardinals</p>
  <p>Seattle Seahawks</p>
  <p>St.Louis Rams</p>
</div>

<input type="button" value="change background color" onClick="changeIt()">   

</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:28:04+00:00Added an answer on May 29, 2026 at 9:28 am

    Background colour is a problem. It is denoted in javascript as backgroundColor. In fact, I think all javascript notations of a css style use camels as opposed to the dash.

    Also, you will need to pick a position of the getElementsByTagName array for the javascript to get the parent of it. parentNode works by getting the parent of a specific element. Not an array of elements.

    function changeIt() {
      var node;
      node = document.getElementsByTagName("p")[0].parentNode;
      node.style.backgroundColor = '#0033dd';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a simple error message that should disapear on page
I am trying to create a simple page that enters data in to a
I'm trying to create a fairly simple piece of JavaScript that displays a random
I am trying to create a Word document with a very simple word macro.
I'm trying to create a simple timer in javascript that counts down from 5
Trying to make simple jQuery function to create a scrollToTop button that fades in
I'm trying to create a simple table of contents (the document is only 4
I'm trying to create a simple login system that will have the forms and
I'm trying to create create a simple word template on the fly which would
I'm trying to create a simple app that draws rectangles within the Canvas tag.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.