I want to add a class to the body tag without waiting for the DOM to load, but I want to know if the following approach will be valid. I'm more concerned about reality than browsers now support.
<body> $("body").addClass("active"); ... </body>
Thanks Steve
. The elementReady () plugin seems to be very close to what you are looking for.
It works with a loop setIntervalthat completes as soon as it document.getElementById()returns an element for the given id.
setInterval
document.getElementById()
id
Perhaps you can make a small modification to this plugin (or commit an update / patch) to allow common selectors (at least for "tagNames") instead of just ids.
, - - setInterval hacking
javascript , , @JasonBunting, .
DOM, , . $(document).ready(), . , .
<body> <div id='topStories'></div> <script type='text/javascript'> $('div#topStories').addClass('active'); </script> </body>
, $(document).ready().
: . -, , , , . :
<html> <head> <style type="text/css"> .foobar { background-color: #CCC; } </style> </head> <body> <script type="text/javascript"> window.document.body.className = "foobar"; </script> <div style="border: solid 1px"><br /></div> <script type="text/javascript"> // happens before DOM is fully loaded: alert(window.document.body.className); </script> <span>Appears after the alert() call.</span> </body> </html>
IE 7, alert(), , ( , DOM ).
alert()
Firefox alert().
, , .
, - . IE6 Firefox 2 ( ), DOM , ( XHTML). , jQuery , , , , "" . :
<script> $(document).ready(function() { $("body").addClass("active"); }); </script> <body> .. .. .. </body>
javascript.
, :
<body class="active"> </body>
.
, JavaScript , JavaScript. , , DOM , , . , "" body , , JavaScript, , , .
, , , , Firefox4, .
, , , , ficker (, ). JS, - ...
Instead of adding a class to your <body>, it might be easier for you to add a class to your <html> tag:
<script type="text/javascript"> document.documentElement.className = 'active'; </script>
Source: https://habr.com/ru/post/1698772/More articles:JQuery user interface: date picker selection on datepicker - jqueryVista Office Interop not working - c #Configuring a backup database server in an ASP.NET web.config file - sql-serverURL Based Authentication Link - securityHow to change the format of substitution variables in a template - unixHow to get a list of domain user accounts using win32 api? - c ++Joining Time Series - c #Processing large (over 1 gigabyte) files in PHP using stream_filter_ * - phpUsing Nagios / Monit / Munin with Windows - monitoringКак сделать прокручиваемый UIView в моем приложении iPhone? - iphoneAll Articles