html - how get content of div via javascript -


i'm trying content of div named 'topage' , did code

<script type="text/javascript">         var topagge = document.getelementsbyclassname("topage");              console.log(topagge);           </script> 

in console shows :

htmlcollection[1] 0: span.topage ... innertext:"mycontentofdiv" length: 1 proto: htmlcollection

i want innertext value , try code :

 console.log(topagge.innertext); 

but in console it's undefined

please how can content of collection html object ( using attribut 0 : span.topage wich contain innertext.

you need wait until html docuemnt loaded. try this:

<script type="text/javascript"> window.onload = function(){     var topagge = document.getelementsbyclassname("topage");     console.log(topagge); } </script> 

edit:

window.getelementsbyclassname returns array of elements; then, following code html content of first element:

topagge[0].innerhtml 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -