[英]Run JS code when all HTML has loaded (not images)
I want to execute a js code which adds a class to all elements that have specific class eg. 我想执行一个js代码,将一个类添加到具有特定类的所有元素,例如。
.lookbook-block
however, I think I'd have to wait until all the HTML has loaded before this loop is executed, but the page had a lot of images so I don't want to use window.load ad that will wait until all images have loaded, which will delay the execution. .lookbook-block
但是,我认为我必须等到所有HTML加载完毕后才能执行此循环,但是页面上有很多图像,所以我不想使用window.load广告来等待直到所有图像均已加载,这将延迟执行。 Is there a way I can wait until only the HTML has loaded? 有没有办法可以等到只有HTML加载完毕?
Thanks! 谢谢!
将脚本放在html的底部
$(function() {
// Your code here.
});
This adds a callback function to execute when the ready
event is triggered from the jQuery library. 当从jQuery库触发
ready
事件时,这将添加一个回调函数来执行。 You can read more about it here . 您可以在此处了解更多信息。 You can do the same thing by using this, which is more clear:
您可以使用以下方法做同样的事情,这更加清楚:
$(document).ready(function() {
// Your code
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.