简体   繁体   中英

jQuery: How to fire event when an element is empty or when element has children

How can I write a jQuery script that will keep an eye on an element's children.

If the element has no children => scrolling for the whole page is enabled (as default) If the element has children => scrolling for the whole page is disabled

Scrolling actions are:

Deactivate scrolling: jQuery("body").mousewheel(function(event,data){event.preventDefault();return false;});
Activate scrolling:   jQuery("body").unbind("mousewheel");

Thank you for your help.

You can use window.setInterval("javascript function", milliseconds) function. Have in mind that the second parameter is the interval in miliseconds. In the example the interval is 1000 miliseconds = 1 second

var interval = window.setInterval(function(){
   //check for children here
}, 1000)

You can get more information about the timing events in java script here: http://www.w3schools.com/js/js_timing.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM