Hi,
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, should we take care to make sure this does not happen?
Thanks
Hi,
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, 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?