Xitcod13
Xitcod13

Reputation: 6079

Test if element with an input type text exists jquery

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??

Upvotes: 0

Views: 1422

Answers (3)

Adil
Adil

Reputation: 148110

Do it like this, Demo on JsFiddle

With jQuery

$('#id').length > 0

With Javascript

if(document.getElementById('ID') != null)
{
    alert("Element found");
}

Upvotes: 1

Shyju
Shyju

Reputation: 218722

length property is not returning the characters in the element. but the number of elements in the jQuery object. So you should be good to use length property in your case.

Upvotes: 2

Ram
Ram

Reputation: 144659

there is a typo in the code!?

$('#id').length > 0

Upvotes: 1

Related Questions