All the answers I could find recommended adding display:none to css… but for a user without javascript, they will never see the element.
jQuery(document).ready(function($){
$('#toggleElm').hide();
$('#toggleBtn').click(function(){
$('#shareLink').slideToggle();
})
});
still results in an element that appears and disappears during page load because the page begins rendering before the DOM has finished these days.
<script type='javascript'>
document.write("<style type='text/css'> #toggleElm {display:none} </style>");
</script>
at the top of the body just seems too hacky.
to prevent the javascript FOUC and let your page fully accessible you should apply a
.no-jsclass in<html>element and then use that class to style your elements, exactly as html5 boilerplate+modernizr doof course you have to remove that class via javascript soon in the
<head>of your document, with a script like thisso if javascript is enabled, it will turn the
.no-jsclass into.jsclass.Using this approach, your page is still accessible even when javascript is not available, because in that scenario the last CSS rule will be applied, leaving your elements visible and accessible.