check if element is inserted on page

Possible Duplicate:
Is there an “exists” function for jQuery

Is there a better way to check if the element is already inserted on page? I'm currently doing this and is working fine, but doesn't seem for me to be the best/fast way

$(element).closest('body').length > 0

Thanks.

Edit:

I doesn't need to know if my element exists, I need to know if it's on page.


你可以使用jQuery内置的.has功能,所以你的代码应该看起来像这样:

$('body').has(element)

Try this :

$(element, 'body').size() > 0

It will fetch for the element within the body.


What you are doing is searching for element "body". It's not what you are looking for

$(element).length > 0

check whether an element exists

链接地址: http://www.djcxy.com/p/14690.html

上一篇: 简单的Javascript执行

下一篇: 检查页面上是否插入元素