我想知道是否可以制作IF
语句,如果容器(父div)包含/不包含某个div ....
<div class="parent" id="x">need to check if div id "n" is here....</div>
所以,IF
父容器(“x
”)不包含div“n
”,然后插入它(我已经知道该怎么做)。
以上甚至可以实现吗?
JS和JQuery可以顺便使用..
由于
答案 0 :(得分:3)
只需使用jQuery.contains
即可var x = document.getElementById('x');
var n = document.getElementById('n');
if (jQuery.contains(x, n)) {
// it does
}
答案 1 :(得分:3)
尝试这个
$('#id:not(:has(#n))')