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>
<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
What I get: 4
What I expect: 2