how do i call a function to count the number of divs with an id of ‘d1’ after the page loads. right now i have it in my section but doesnt that execute the script before anything in the loads? because it works if i put the code below the div tags…
Share
Firstly there should be at most one because IDs aren’t meant to be repeated.
Second, in straight Javascript you can call
getElementById()to verify it exists orgetElementsByTagName()to loop through all the divs and count the number that match your criteria.or
But I can’t guarantee the correct behaviour of this because like I said, IDs are meant to be unique and when they’re not behaviour is undefined.