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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:47:01+00:00 2026-06-13T21:47:01+00:00

CSS: ol{display: block;} // display: ; throws an error in the console(FF) HTML: <!DOCTYPE

  • 0

CSS:

ol{display: block;} // display: ""; throws an error in the console(FF)

HTML:

<!DOCTYPE html>
<html>
<head><script type="text/javascript">!js is here!</script>
<body>
<h2>Title</h2>
<input type="button" id="btn" value="expand" />
<ol>
    <li>Value 1</li>
    <li>Value 1</li>
    <li>Value 1</li>
</ol>
</body>
</html>

Javascript: // trying to just hide the element for now

window.onload = function() {
    function expand() {
        var ol = document.getElementByTagName('ol');
        ol.style.display('none');
    }
    function init() {
        var btn = document.getElementById('btn');
        btn.addEventListener('click', expand, false);
    }
}

I’ve been searching high and low for something similar, everything I found used an additional library(utility.js, jquery etc.), but for learning purposes I want to do this in pure JS.

Every source online cites element.className = "newClass";. I tried that by making a class .hide{display: none;} and .show{display: "";}, but it doesn’t seem to do anything. Then I switched to manipulating the style (element.style.display("none");), but that doesn’t seem to work either.

  • 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-13T21:47:03+00:00Added an answer on June 13, 2026 at 9:47 pm

    As your JavaScript appears before the elements are loaded into the DOM, you need to wait until the window has loaded (or document is ready, not shown in this snippet) before adding the event listeners to the button.

    window.addEventListener('load', function() {
      document.getElementById('btn').addEventListener('click', function(e) {
        var style = document.getElementsByTagName('ol')[0].style;
        style.display = (style.display == 'none') ? 'block' : 'none';
      }, true);
    }, true);
    

    To toggle display, you can use the display CSS attribute set to either block for displayed as a block element, or none for not displayed at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

JQUERY: <script type=text/javascript> $(document).ready(function() { $('li.directory > ul').css('display','none'); $('li.directory').click(function () { $(this).toggleClass('expanded'); $('ul', this).slideToggle('slow');
I have a page like below; <style type=text/css> #test a{ display: block; width: 150px;
<script> $(#tableview).css({'display' : block}); $(#tableview).append('{{html}}'); or $(#tableview).html('{{html}}'); </script> <div id=tableview style=display:none;></div> the {{html}} i.e,
my code is something like this //css li{display:inline-block} //html #li margin and width are
I have html and css as below - .title { display: block; background-color: red;
here is my code: $(a).live('click', function(){ history.pushState({}, '', this.href); popstate(this.href); $(#loadpage).css(display, block); return false;
my CSS code .child{ width:100px; height:100px; display:inline-block; } my HTML code <div id=parent> <div
My javascript runs like this on firebug: tr=$(this).parent('tr'); tr.find('.img-delete').css('display','block'); but I can't see the
I just got a script to work by changing $('#thisElement').show(); to $('#thisElement').css({'display':'block'}); where #thisElement
My Css #container{ display:block; } #container ul{ list-style:none; position:relative; margin:0px; padding:0px; display:block; } #container

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.