javascript - JQuery - If ( $ ('#products' ).existOn.(document) ) == true {//这样做}

标签 javascript jquery html if-statement conditional-statements

我如何创建这个条件分支。如果带有 ID 产品的 HTML 代码中?如果 #products 确实存在于实际文档中?

感谢您的回复!

伪 Javascript (JQuery)

If ( $('#products').existOn.(document) ) == true { 
   //do this
}

最佳答案

使用length :

if ( $('#products').length > 0){ 
   // element is present
}

关于javascript - JQuery - If ( $ ('#products' ).existOn.(document) ) == true {//这样做},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4655743/

相关文章:

javascript - HTML-CSS 布局使整个网站居中并卡住菜单

html - 样式不会被覆盖

php - 我需要在不使用 JavaScript 的情况下验证我的表单

javascript - 带有 jQ​​uery 插件的 jQuery 对象文字或模块模式

javascript - 将所有方法绑定(bind)到 'this'

javascript - Spring 和 Angular - 非常简单的 REST 请求

javascript - 按子元素的数据 ID 对 li 进行排序 - jQuery

javascript - 我可以使事件在发起者和后代之间传播吗?

javascript - 在 jquery 中传递 "this"上下文

javascript - jQuery 更改事件被调用两次