Onlick event help?

I have a button with onclick event and when i clicked the button all html content is hidden. why?

1 Like

Maybe someone else understands the details, but it appears that there is already a function called open in that namespace. When I rename the function, it works as expected.

1 Like

Hi @yasinkarax,

open() (open a new browser window) and close() are already exciting in JavaScript ( If you change the name of your functions, it should work. Also, don’t forget to correct how you opened your function:

function open(){
  function open(){
  var nav = document.getElementById('nav'); = 'none';

Remove the first line and you are good I guess.


As @LucLH said, the “open()” is a pre-existing function name.

“The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.” Window open() Method (
So you can use it to specify certain details when opened (URL, name, specs), you can see a quick list of these at that same site.

May I ask you (@yasinkarax) what the goal for you is with the button? Is it to scroll back up to a navigation bar that is meant to be fixed or is it to open a new tab with the navigation bar in horisontal view? Or is it to have the vertical navigation bar hidden and when the button is pressed it should become visable/interactive or something similar?

Might be easier to get good advice for an appropriate code from someone, if they understand the future goal of its use. It could be useful to just use “function open()” in some cases.

1 Like

Thank you for explanation

I am trying to do some html css js examples. My porpose with this button is making some drop down menu left to right.

Sorry, but I am still not sure I understand what you mean. At the moment it looks like you have a navigation bar on the left (a menu going from upper left to bottom left).
Did you want the user to click the button and the menu switches to being at the top (going from upper left to upper right, while being on a single row) or do you want to make a dropdown menu when the button is clicked? Or do you maybe want the navigation bar to appear once you click the button? Perhaps this link could be useful for you: How to Create an HTML Dropdown Menu [+ Examples] (

The happiness of the woman featured at the top of this Post, seems ill-proportioned to the task at hand… that of Creating a Drop-Down Menu.

At the beginnig the menu will be hidden. when user clicked the button the menu will be visible with some animation.

I see, then perhaps this post could be useful to check out to get some inspriation on how the hiding/showing could be done: How To Toggle Between Hiding And Showing an Element (

1 Like

yes, ı am also trying to those examples in w3schools how to page.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.