I am currently following an online class and I can't understand why I don't have the same thing as the teach in my console.
I have an h1 in my HTML, followed by this :
<script type="text/javascript">
console.log(document.querySelector('h1'));
</script>
I am supposed to get the content of the h1 in my console but it returns me the selector title. I have not found something that could help me in @.. (and just to be sure I tried it on several browsers).
EDIT : I am supposed to get this : [1]: https://i.stack.imgur.com/LYXbs.png And i get this : [2]: https://i.stack.imgur.com/FLuH8.png
CodePudding user response:
Add .innerText
after the querySelector to get the text:
console.log(document.querySelector('h1').innerText);
<h1>Text</h1>
CodePudding user response:
you just need to add the .innerHTML at the end.
<script type="text/javascript">
console.log(document.querySelector('h1').innerHTML);
</script>