I would like to test if an element exists but i cannot do it with $('#id')length > 0 because i am testing an input element which might not contain any characters and then it results in 0 even if it exists...
How can i test if this element exists??
there is a typo in the code!?
$('#id').length > 0
if ($("#id").text() != "")?Do it like this, Demo on JsFiddle
With jQuery
$('#id').length > 0
With Javascript
if(document.getElementById('ID') != null)
{
alert("Element found");
}
$('Anything') always returns jQuery object. It is never null. -1 >> jsfiddle.net/skram/RewrK <<
$('#id').show()because jQuery internally will call the function only if it finds one or more matching elements.