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 8213453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:07:24+00:00 2026-06-07T11:07:24+00:00

I am attempting the understand the use of the document object type and to

  • 0

I am attempting the understand the use of the document object type and to challenge myself I am trying to hide all the div tags. When I execute the function, I am returned the error Uncaught TypeError: Cannot set property 'display' of undefined however am unsure what it means exactly. What is undefined?

The output of the code can be found at http://jsfiddle.net/Bdbtq/

Code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta http-equiv="content-language" content="en-us" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="pragma" content="no-cache" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta name="author" content="" />
    <meta name="copyright" content="&copy; 2012" />
    <meta name="robot" content="noindex, nofollow" />

    <title>js features</title>

    <base href="" />

    <link rel="stylesheet" type="text/css" media="all" href="" />

    <style type="text/css" media="all">

    </style>
</head>
<body>
    <div id="container">
        <div id="header"></div>
        <div id="content">
            <p>This is sample content</p>
        </div>
        <div id="footer">&copy; 2012</div>
    </div>

    <script type="text/javascript">

    function hideMe() {
        //hide all div elements
        var div = document.getElementsByTagName("div");

        for(var i = 0; i < div.length; i = i + 1) {
            div.style.display="none";
        }
    }

    </script>
    <p onClick="hideMe();">Click to hide</p>
</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-06-07T11:07:26+00:00Added an answer on June 7, 2026 at 11:07 am

    getElementsByTagName returns an array. So you need:

        var divs = document.getElementsByTagName("div");
    
        for(var i = 0; i < divs.length; i = i + 1) {
            divs[i].style.display="none";
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to use an HttpDelete object to invoke a web service's delete method.
I am attempting to use the haml-jekyll-extension only I do not understand how to
I've been trying to use twitter4J and this tut ( http://java-tutorial.ch/framework/twitter-with-java-tutorial ) in attempting
I am attempting to understand and use Windows Workflow Foundation (WF) and I find
I'm attempting to use NHibernate to serialize a moderately complex object graph* Actual mapping
I am attempting to understand the c library qsort in the context of pointers
Having never used awk before on Linux I am attempting to understand how it
Attempting to use the data series from this example no longer passes the JSONLint
Attempting to use XStream's JavaBeanConverter and running into an issue. Most likely I'm missng
I'm attempting to use the OpenAmplify API to evaluate the content of a URI.

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.