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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:32:11+00:00 2026-05-28T15:32:11+00:00

I am trying to build a little toggle switch which removes line numbers on

  • 0

I am trying to build a little toggle switch which removes line numbers on click.

I have got it working here: http://www.webdevout.net/test?09&raw

It is code highlighted by Geshi, and i build the javascript at the top to toggle line numbers.

This works fine, but what I would really want is that when the line numbers are ‘hidden’, that it also removes that gap on the left. So that the actual code fills the screen.

If clicked again, the lines numbers would come back again.

  • 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-28T15:32:11+00:00Added an answer on May 28, 2026 at 3:32 pm

    You have to change the ol element’s padding to 0:

    document.getElementsByTagName("ol")[0].style.padding = '0';
    

    Above script is assuming you only have one <ol> in your document, or at least the first one is the one you’d like to edit.

    EDIT

    You would have to switch between

    document.getElementsByTagName("ol")[0].style.paddingLeft = '20px';
    

    and

    document.getElementsByTagName("ol")[0].style.paddingLeft = '0px';
    

    Your approach is a tad bit wrong though, you should be changing the listStyle of the <ol> tag and not of the individual <li> tags.

    document.getElementsByTagName("ol")[0].style.listStyle = 'none';
    

    and

    document.getElementsByTagName("ol")[0].style.listStyle = 'decimal';
    

    EDIT2 Perhaps give this a try. If you could also link me to it, I can test it in chrome and firefox as well. Maybe I’m not getting your problem..

    function toggle_visibility() {
         var e = document.getElementsByTagName("ol")[0];
         if(e.style.listStyle == 'none') {
           e.style.listStyle = 'decimal';
           e.style.paddingLeft = '20px';
         } else {
           e.style.listStyle = 'none';
           e.style.paddingLeft = '0px';
         }
      }
    }
    

    Link

    <a onclick="toggle_visibility();">toggle</a> 
    

    EDIT3

    Ah, I found the problem 🙂

    if(document.getElementsByTagName("ol")[0].style.listStyle.substr(0,4) == 'none')
    

    Because when you set the listStyle to ‘none’ it actually gets set to ‘none outside none’ by firefox and IE. So if you use .substr(0,4) to get the first 4 characters to compare to none, you should be fine 🙂

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

Sidebar

Related Questions

I'm trying to build a little calendar in JavaScript. I have my dates working
I have a site I'm trying to build and I've hit one little snag
I've been trying to build evaldictator on OSX. Unfortunately I have little to no
I've been trying to build a little bot which will be using Reddit's API.
I'm trying to build a little script that would let me do this: http://example.com/appicons.php?id=284417350
Ive got a live update twitter thing that i have been trying to build,
I am trying to build a little javascript class for geocoding addresses trough Google
I am trying to build my own little toolbox for Vista. One of the
I'm trying build a method which returns the shortest path from one node to
Trying to build sslsniff on a RHEL 5.2 system here. When compiling sslsniff on

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.