In JavaScript, you can store references to HTML elements using variables by selecting them through methods like document.getElementById(), document.querySelector(), or document.getElementsByClassName(). Here are some examples:
// Using getElementById
var header = document.getElementById('headerId');
// Using querySelector
var button = document.querySelector('.buttonClass');
// Using getElementsByClassName
var items = document.getElementsByClassName('itemClass');
In these examples:
headerstores a reference to an element with the IDheaderId.buttonstores a reference to the first element with the classbuttonClass.itemsstores a collection of elements with the classitemClass.
You can then manipulate these elements using the stored references.
