E
E
eellazy2015-10-11 09:54:40
JavaScript
eellazy, 2015-10-11 09:54:40

Why does the function only work on the second click?

Why does the function only work on the second click? With one click, nothing happens. This happens when you reload the page.

function openbox(id){
    display = document.getElementById(id).style.display;

    if(display=='none'){
       document.getElementById(id).style.display='block';
    }else{
       document.getElementById(id).style.display='none';
    }
}




<div class="ac" onclick="openbox('box'); return false"><?php profile_picture_show(); ?></div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-10-11
@eellazy

Because you're reading the value through style.display and it's coming from the style attribute. For the first time, nothing was written in it. You here - https://learn.javascript.ru/styles-and-classes#th...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question