What's the result of a selector with no matches?
What happens when you use a selector like this:
$('#myelement').remove();
but no element with id 'myelement' is actually part of the page? Is it undefined, 开发者_Python百科should we take care to make sure this does not happen?
Thanks
jQuery will take care of it: no errors will be thrown if element is not on the page. It also the same behavior for other jQ methods - it's not necessary to check if element presents on the page.
If you want make sure that element is on the page:
if($('#myElement').size()) {
}
JQuery will take care of this but i think you want to figure out what you are doing as JQuery may help mask some underlying issue where you believe that item is there?
精彩评论