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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:34:14+00:00 2026-05-26T11:34:14+00:00

How would you write a toggle which toggles the display property of an element

  • 0

How would you write a toggle which toggles the display property of an element onmouseover/onmouseout from display:none to display:block;, or regardless, any css property which jquery’s toggle can operate on- how exactly would you write a toggle function without jquery?

And why can’t you take a javascript css property as a boolean in the following code?

<html>
<head>
<style type="text/css">
a {
 display:none;
}
</style>
<script type="text/javascript">

 function ab(a)
 {
   if(document.getElementById(a).style.display=='none')
   {
     document.getElementById(a).style.display="block";

  }
  else if(document.getElementById(a).style.display=="block")
   {
     document.getElementById(a).style.display="none";

    }
  }

 </script> 
 </head>
 <body>
 <div class="fg">
 <div style="width:100px;height:100px;border:2px solid blue;" onmouseover="ab('g');"
      onmouseout="ab('g');">
  <a id="g" href="http://www.dfadsafafa.com">lajflke</a></div></div>
 </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-26T11:34:15+00:00Added an answer on May 26, 2026 at 11:34 am

    The solution you mentioned seems fine, but can make it more concise.

    function toggle(id){
        var div1 = document.getElementById(id);
        if (div1.style.display == 'none') {
            div1.style.display = 'block'
        } else {
            div1.style.display = 'none'
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Do you know any library that will help doing that? I would write a
How would you write (in C/C++) a macro which tests if an integer type
I am trying to write a method that will toggle a button from being
Context I'm trying to write myself a script that would toggle my WLAN adapter
In Perl, I would write: $x = abbbc; $x =~ s/(b+)/z/; print Replaced $1
Would you write something like: enum XYZ_TYPE {X=1, Y=2, Z=3}; I saw it and
How would you write a regular expression to convert mark down into HTML? For
How would one write a regular expression to use in Python to split paragraphs?
How would I write a Perl CGI script that receives a file via a
Where would you write an error log file, say ErrorLog.txt , in Windows? Keep

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.