使用jQuery,我以编程方式生成了一堆div是这样的:
Some Text1
Some Text2在我的代码中的其他地方,我需要检测这些DIVs是否存在。div的类名是相同的,但每个div的ID都不同。你知道怎么用jQuery检测它们吗?
发布于 2018-07-27 15:07:55
在Jquery中,您可以这样使用。
if ($(".className")[0]){
// Do something if class exists
} else {
// Do something if class does not exist
}使用JavaScript
if (document.getElementsByClassName("className").length > 0) {
// Do something if class exists
}else{
// Do something if class does not exist......
}https://stackoverflow.com/questions/5783280
复制相似问题