Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- How does this code run?


ewwatson - 2:24 am on Oct 25, 2012 (gmt 0)


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>


Thread source:: http://www.webmasterworld.com/javascript/4512050.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com