Rain Lover
05-25-2019, 08:35 AM
Sample code:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Get elements number</title>
</head>
<body>
<p class="">Hello, world!</p>
<p class="5">Hello, world!</p>
<p class="9">Hello, world!</p>
<p class="">Hello, world!</p>
<script>
console.log(document.querySelectorAll("p[class]").length);
</script>
</body>
</html>
DEMO (https://jsfiddle.net/Mori/dk8r1bx9/)
What I get: 4
What I expect: 2
<!DOCTYPE html>
<html lang="en">
<head>
<title>Get elements number</title>
</head>
<body>
<p class="">Hello, world!</p>
<p class="5">Hello, world!</p>
<p class="9">Hello, world!</p>
<p class="">Hello, world!</p>
<script>
console.log(document.querySelectorAll("p[class]").length);
</script>
</body>
</html>
DEMO (https://jsfiddle.net/Mori/dk8r1bx9/)
What I get: 4
What I expect: 2