JQuery Sprawdź, czy element istnieje
// Check if an element currently exists
if ($('#element').length) {
}
Ugly Unicorn
// Check if an element currently exists
if ($('#element').length) {
}
$(document).ready(function() {
var $myDiv = $('#DivID');
if ( $myDiv.length){
//you can now reuse $myDiv here, without having to select it again.
}
});
if ($('.element').length) {
// there is at least one element matching the selector
}
if ($(selector).length)
if ($("#myElementID").length){
//I exist
}
$(function() {
var $button = $(".the_button");
alert (isStale($button));
$button.remove();
alert (isStale($button));
});
function isStale($elem)
{
return $elem.closest("body").length > 0;
};