开发者

How to check a form is available or not by using its id - jquery

开发者 https://www.devze.com 2023-04-07 23:34 出处:网络
Is it possible to check weather a form is available or not using jquery. For example : 1. I am having a form ID called form1

Is it possible to check weather a form is available or not using jquery.

For example :

1. I am having a form ID called form1

2. I need to check in the page weather the id cont开发者_C百科ains a form or not.

3. How can i achieve it using jquery.

Thanks in advance....


You can use the length property like this:

if ($('#form1').length > 0){
   // form exists
}
else {
   // form does NOT exist
}

Docs:

  • http://api.jquery.com/length/


look after a form + id

if($("form#form1").length > 0) { alert('a form with and id "idname" was found!'); }

or:

var form = $("#form1");
if(form.length > 0 && form[0].tagName === "FORM")  { alert('a form with and id "idnam" was found!'); }

if you want to really check if #form1 is a form.

0

精彩评论

暂无评论...
验证码 换一张
取 消