在以下代码中,alert(el)
输出null
,但我不明白为什么会这样。如果我只写querySelector('div')
,一切都正常。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="./jquery.js"></script>
<title>Document</title>
<style>
div {
width: 200px;
height: 200px;
border: 1px solid black;
background-color: blue;
}
</style>
</head>
<body>
<p>
<div>
Good bye
</div>
</p>
<script>
let el = document.querySelector("p div");
alert(el);
</script>
</body>
</html>