我一直在考虑在第n个子级选择器中使用第n个子级来查找元素。这似乎在火狐中有效,但在chrome上似乎不起作用。下面是我的测试文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>untitled</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script type="text/javascript" charset="utf-8">
myFunc = function() {
if(document.querySelector('#wonderful DIV:nth-child(2) DIV:nth-child(2)')) {
alert("found the element");
} else {
alert("element not found");
}
};
</script>
</head>
<body onLoad="myFunc()">
<div id="wonderful">
<div>
</div>
<div >
<div>
</div>
<div class="blue">
find me!
</div>
</div>
</div>
</body>
</html>
还有没有人看过这个问题?有解决方案来解决这个问题吗?
https://stackoverflow.com/questions/6345358
复制相似问题