How to check that a div exists jquery and if it does do nothing
This question already has an answer here:
检查一个jQuery对象的长度属性
if($('div.errormsg').length==0)
{
//Not exists, so redirect
//window.location.href='newurl';
}
change this:
if (document.getElementById('.errormsg')) {
to this:
if (document.getElementsByClassName('errormsg').length) {
document.getElementsByClassName docs @ MDN
您可以使用.length
属性来检查元素/元素的存在性:
if(!$('.errormsg ').length){//does ot exist
//redirect
}
链接地址: http://www.djcxy.com/p/14688.html
上一篇: 检查页面上是否插入元素