0

This is a curiosity question more than anything. Is there a way to count the psuedo elements that are being added to a page? Recently I was looking at a page and Chrome DevTools showed 5k+ nodes needing layout updates, but doing a document.querySelectorAll('*').length only showed 3k~ nodes in the DOM.

I've yet to find a way to count these elements. I have found ways to set the content in the psuedo elements, but no way to count them!

Jared
  • 5,840
  • 5
  • 49
  • 83
  • 1
    check this: https://stackoverflow.com/a/58001812/8620333 you loop all the element and you check the content of each pseudo element – Temani Afif Nov 25 '19 at 21:59
  • ^ I am already counting there so it's a duplicate – Temani Afif Nov 25 '19 at 22:00
  • @TemaniAfif To be fair, this question asks for how to do it in VanillaJS and that answer uses jQuery... – Heretic Monkey Nov 25 '19 at 22:02
  • edge case: if element has both `:after` and `:before` it will still have single value in `content` property – skyboyer Nov 25 '19 at 22:03
  • 1
    @HereticMonkey yes but the main part is JS `window.getComputedStyle(elem,"before").getPropertyValue("content");` .. the rest is because I am lazy ;) – Temani Afif Nov 25 '19 at 22:03
  • 1
    @TemaniAfif hardly a duplicate. I'm looking for VanillaJS. **ALL** pseudo elements (not just on div) and ideally, something that doesn't _require_ looping! I understand the drive to remove/close duplicates, but some due diligence should be done to make sure it is an actual duplicate and not and extrapolated reach for it to be similar... – Jared Nov 26 '19 at 20:26
  • A duplicate question isn't a question where you will find a *ready-to-copy-past* code. The duplicate already give you how to identify if a pseudo element exist or not and also give you an example code of counting. Now you should do a *small* effort trying to write the code you want by yourself since you have all the element of the puzzle. – Temani Afif Nov 26 '19 at 20:32
  • Inferring the required code isn't an issue, I just consider this a place to find answers. No searches led me to your previous answer. I don't consider it a duplicate considering we don't know the skills of whoever might be looking, but ¯\_(ツ)_/¯ – Jared Nov 26 '19 at 20:37
  • We don't consider skills when closing as duplicate, we only consider the question. Your solution or at least what allow you to find a solution is within the other question so it's a duplicate. If with that you are still not able to write a working code to suit your need then you can edit your question (or ask a new question) where you show your effort but don't simply say: *I'm looking for VanillaJS. ALL pseudo elements (not just on div) something that doesn't require looping*. It's like you are simply saying: *I don't like your code, show me another one*. – Temani Afif Nov 26 '19 at 20:52

0 Answers0