I have been learning JavaScript for a week and because I already have some knowledge in CSS and HTML I was trying to make a simple page with an option to change the body's background picture by pressing a button. I know how to do that by getting the body as a variable. However, I know how to do 'document.getElementByTagName', but I work with Master Pages, which means there is no body
tag at the beginning of the HTML code. What could I do to work around that?
CodePudding user response:
It is getElementsByTagName, since tags can be multiple, same goes for the class. Just for the id it is different.
CodePudding user response:
document.querySelector('body') // will take the first catch of a tag
document.querySelector('.class') // will take the first catch of a class
document.querySelector('#id') // will get the exact id
document.querySelector('[name="first_name"]') // will get the first catch of a custom or existing property as name