简体   繁体   中英

jQuery-ui widget is rendered

How to check if a jQuery-ui widget is rendered or not (version 1.11.2)? To avoid Uncaught Error: cannot call methods on xxxx prior to initialization; attempted to call method 'xxxx' Uncaught Error: cannot call methods on xxxx prior to initialization; attempted to call method 'xxxx' errors.

One way is to use the data api like

If your widget name is datepicker and the element id is date then

if($('#date').data('datepicker')){
    //call method since it is initialized
}

Demo: Fiddle


The same can be done via the :data() selector

if ($('#date').is(':data(datepicker)')) {
    //call method since it is initialized
}

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