+ 2
Call a function, when a new element gets created
I want to know how many "p" elements exist in this document and want to call a function, when another one gets appended to the body. when i do the qurtySelectorAll("p").length Method, i only know how many elements are existing right at the moment when i do the Method. But then, an other element gets created the number upon is wrong. I want to call a function when a new this number changes. Please ask, if you do not understand something in this question https://code.sololearn.com/Wi5BeYtoirGR/?ref=app
7 odpowiedzi
0
Hi Sebay
query selector returns a static nodelist. You want to use getElement by Class/tagname /name which returns a live nodelist, and is kept updated.
+ 4
Make a counter variable that goes up by 1 everytime you make a new p element
+ 1
Sebay document.getElementsByTagName("p").length should return the number of p tags
+ 1
Thx @Mike Choy
Worx
0
Call your other function inside the elem function
0
Both ideas are good, but i can not edit the given code
So i am not able to insert a counter, neither a function inside the elem function
This is just an example which should make it easier to understand the question
0
but then some new elements appear and again i do not got the correct number of p elements