The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> How to get the number of elements with a non-empty class name
RainLover
post May 25 2019, 03:36 AM
Post #1


Advanced Member
****

Group: Members
Posts: 216
Joined: 16-November 09
Member No.: 10,346



Sample code:

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

What I get: 4
What I expect: 2
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
Christian J
post May 26 2019, 05:22 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,649
Joined: 10-August 06
Member No.: 7



You're welcome!

No, you must do it manually. tongue.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 16th April 2024 - 06:28 PM