I have implemented the Jquery toggle method to display a div when a button is clicked
$("button").click(function(){
$("#divId").toggle();
});
Everything is functioning properly, but the issue is that the default setting displays the div or sets the css property display:block
. This means that when the page loads initially, the div is visible and I must click the button to hide it.
Some suggestions from others advised me to modify the css property to resolve this problem. However, I am hesitant as this would conceal the div and could lead to issues if the user had disabled JavaScript for any reason.
My preference is to use JavaScript to hide the div initially before letting Jquery's toggle method take over. I attempted to use
document.getElementById(divId).style.dsplay="none"
placed just before the toggle method, but this approach results in the toggle function not working correctly - it simply hides the div permanently.