JavaScript onclick requires two clicks

前端 未结 8 1062
执笔经年
执笔经年 2021-01-14 19:33

My problem is that when onclicktriggers the toggleNew function it\'s not executing but when I click the div a second time it\'s execut

8条回答
  •  不知归路
    2021-01-14 20:19

    This will not work properly because you are using following line inside 'div#aside_main' which is going to be hidden.

     
    click

    Try keeping it outside like this-

    click
    content
    content2

    Also in javascript it is not checking for 'e.style.display' first time in if condition.

    Try using

        if(e.offsetWidth > 0 || e.offsetHeight > 0){
          e.style.display = 'none';
          se.style.display = 'block';
        }
        else
        {
          e.style.display = 'block';
          se.style.display = 'none';
        }
    

提交回复
热议问题