How does this code run? This is using jQuery to use JS to run CSS. For times when JS is off. Works perfect. It adds the class .js-on to the html if js in on. My question is this? I want to place all this code at the bottom of the page. I was surprised it works this way. Does the browser have to travel all the way back up to find the html tag (thus slowing it down?) or does it work different. I have 5 different ways to do this. I’m looking for the fastest. This way is clean because I already have jquery library on the page. Thanks.
<script type=“text/javascript” src=“jquery.js”></script>
<script type=“text/javascript”>
$(‘html’).addClass(‘js-on’);
</script>
<style type=“text/css”>
html.js-on #method1 {color:red;}
</style>
<p id=“method1”>Method #1</p>
I’ll just ask. What’s the fasted out of these five methods if I need/want to place the needed code at the bottom of the page? Unfortunately I don’t know enough about js to answer that myself. Reason being I have a large photo gallery that needs to load and I don’t want any extra markup slowing it down. http://www.visibilityinherit.com/code/add-css-with-javascript.php