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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:02:35+00:00 2026-06-17T14:02:35+00:00

I am trying to hide some elements after document loaded. I manage to do

  • 0

I am trying to hide some elements after document loaded. I manage to do this with getElementById but can’t manage to do this while using getElementsByClassName or getElementsByTagName.

I have read lots questions and answers but coundn’t find the solution. Here is sample fiddle.

javascript:

function myFunction() {
  document.getElementById("b").style.display="none";
  document.getElementsByTagName('p').style.display="none";
  document.getElementsByClassName("a").style.display="none";
}
onload = myFunction;

html:

<p>Tag Ele Test</p>
<p class="a">Class Test</p>
<p id="b">ID Test</p>
  • 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-17T14:02:36+00:00Added an answer on June 17, 2026 at 2:02 pm

    getElements (byTagName, byClassName) does return a NodeList, which you need to iterate over. It has no single style declaration property.

    var element = document.getElementById("b");
    if (element != null)
        element.style.display = "none";
    var elements = document.getElementsByTagName('p');
    for (var i=0; i<elements.length; i++)
        elements[i].style.display = "none";
    elements = document.getElementsByClassName("a");
    for (var i=0; i<elements.length; i++)
        elements[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 trying to show and hide some elements(span) using jquery fadeIn and fadeOut
For some reason I can't hide WPF Toolkit's DataGridColumn. I am trying to do
I'm trying to use the ClientHandler.validateMatches() method to hide/display and enable/disable some elements of
I found documentation that states I can hide some of the UI elements in
I am trying to write some Javascript to hide some elements that contain only
I'm trying to show and hide some metadata elements inside and overlay DIV based
I'm trying to hide some divs that I have created dynamically using the .hide()
I'm trying to layer some elements using z-index and it's not working at all.
I'm trying to hide some of my Perl program from the end user to
I'm trying to hide some unused journals. It seems in older versions, journals had

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.