JavaScript 2022

Term 3 Wednesday

May - July 2022

This site will be updated live during the sessions

Week 4 Example 3

JavaScript

JavaScript

Using querySelectAll

JQUERY

QuerySelectAll can be used with an element by using the tag name as an argument

contentElement.querySelectorAll('h1');

Or a class: contentElement.querySelectorAll('.className');

QuerySelector will get the first element/first elemet with class name found

It also works well with an id

document.querySelector("#thisSentence")

		
001window.onload = function(){
		
002	const contentElement = document.getElementById('content');
		
003	const heading1Elements = contentElement.querySelectorAll('h1');
		
004	heading1Elements.forEach(function(heading1)
		
005	{
		
006		console.log(heading1);
		
007	});
		
008	console.log(document.querySelector("#thisSentence"));
		
009}