Message from JavaScript discussions

May 2019

— Please i want to select all the textContents of h2 element

— 

There cannot be duplicate ids I'd suggest you use a class and then use document.getElementsbyClassName('selector')

— Tried it
didn't work

— Besides, i didn't use id on the post, i used element tage

— So it would go like

<h2 class="foo">Bar</h2>
<h2 class="foo">Bar</h2>
<h2 class="foo">Bar</h2>
<script>
let elements=document.getElementsByClassName('foo')
var element_values = [ ]
elements.forEach(element =>{
element_values.push(element.innerHTML)
})
console.log(element_values)
</script>

Message permanent page

— .

— You're opening and closing body tag before the markup

— I used forloop but it loop through only the first h2 element

— You're closing the body before your first h2 element

— Remove that closing body tag

— Sorry about that but say result

— Show the code.