$(document).ready(function () { $("#menu").hover( function () { $('#hide').show(); // #hide = display:none; }, function () { $('#hide').hide(); } ); }); If you just write $ ("# menu"). Click or $ ("# menu"). OnClick, nothing happens.
$(document).ready(function () { $("#menu").hover( function () { $('#hide').show(); // #hide = display:none; }, function () { $('#hide').hide(); } ); }); If you just write $ ("# menu"). Click or $ ("# menu"). OnClick, nothing happens.
Use toggle :
$(document).ready(function () { $("#menu").click(function() { $('#hide').toggle() }); }); #menu on #menu will open / hide the block - YuriI decided all pure JS `th! It is not clear why jquery was invented.
function toggle_visibility(id) { var e = document.getElementById(id); if(e.style.display == 'block') e.style.display = 'none'; else e.style.display = 'block'; } In html write so:
<a href="#" onclick="toggle_visibility('foo');"> <div id="foo">This is foo</div> So?
$(document).ready(function () { $("#menu").on('click', function() { function () { $('#hide').show(); // #hide = display:none; }, function () { $('#hide').hide(); } }); }); This is if you match the question itself. Hovering replaced by a click, if you want to create a state replacement, then you need toggle, as other commentators said.
Source: https://ru.stackoverflow.com/questions/614764/
All Articles