-1

Alright so here is my code:

<!DOCTYPE html>
<html>

<head>
    <!-- head definitions go here -->
</head>

<body>
    <textarea id="txtArea"></textarea>
    <button id="btn1" onclick="convertHTML()">
        Analyse
    </button>
    <button id="btn2">
        Clear
    </button>
    <div id="output">

    </div>


    <script>
        function clearTxtArea() {

        }
        function convertHTML() {
            var html = document.getElementById('txtArea').value; //Idk of dit werkt lets see
            var doc = new DOMParser().parseFromString(html, "text/xml"); //Zet code om van "<div> fzfhez </div>" etc naar echte HTML elementen
            
            console.log(doc)
            
        }
    </script>
</body>

</html>

And basically I want to turn the data from the txtArea into html elements (so the input would be like <a>ono<div>test</div></a> ) and I want my code to loop trough all elements etc and give me a json list of how many a elements and how many div's etc there are displayed

Andreas
  • 21,535
  • 7
  • 47
  • 56
Gevzzz
  • 7

1 Answers1

0

If you want to just count the a elements user inputted put above your console log this code:

const a = document.querySelectorAll("a");

console.log(a.length);
console.log(a); // element list
Kudlas
  • 659
  • 7
  • 24