How To Check Htmlelement Object Exists In Dom
I have htmlElement object and I need check it on exists in DOM: It doesn't exist by selector. $(htmlElement).length // 1 $(htmlElement)[0].className // k-button k-state-hover $(h
Solution 1:
You can check whether the DOM contains htmlElement
with
if ($.contains(document, $(htmlElement)){
// htmlElement is attached to the DOM
}
Solution 2:
In order to give proper condition you always need to check length of object
i.e if($("li.k-button.k-state-hover").length)
Solution 3:
Try with javascript:
var ele = document.getElementById('yourId');
or
var ele = document.getElementByTagName('tag name');
if (typeof(ele) != 'undefined' && ele != null)
{
// exists.
}
Solution 4:
if(htmlElement.length > 0) {
//Do what you need
}
or
if($('tag').length > 0) {
//YOUR CODE
}
Post a Comment for "How To Check Htmlelement Object Exists In Dom"