Robbie N Erika Stokes Robbie N Erika Stokes - 1 month ago 5
jQuery Question

My Function isn't working?

I'm trying to hide the chatname

div
and when hidden put the
chatid
at the bottom that's where the
64px
for but its giving me a error saying


toggle 3();
not defined


<div id="chatdiv">
<div id='chatid' onclick="toggle3();">
<div id="chatname">
</div>
</div>
</div>





var toggle3 = function() {
var mydiv3 = document.getElementById('chatid');
var mydiv4 = document.getElementById('chatname');
if (mydiv4.style.height === '0px' || mydiv4.style.height === '' )
mydiv4.style.height = '516px';
mydiv3.style.top = "64px"

else
mydiv4.style.height = '0px'
mydiv3.style.top = "auto"

}

Answer

i am not sure but it seem you want to do this

  <div id="chatdiv">
     <div id='chatid' onclick="toggle3();" >
        <div id="chatname">
        </div>
      </div>
     </div>

var toggle3 = function() 
{
console.log(this.id);
var mydiv3 = document.getElementById('chatid');
var mydiv4 = document.getElementById('chatname');
if (mydiv4.style.height === '0px' || mydiv4.style.height === '' )
{
mydiv4.style.height = '516px';
mydiv3.style.top = "64px"
}
else
{
mydiv4.style.height = '0px'
mydiv3.style.top = "auto"
}
}

javascript code should enclosed by script tag other then if there are multiple expression in if else block you must have to use code block.

Comments