I want to make a function that instead of using a parameter, it will get the value before the dot like any JavaScript method works. This is what I have that works using a parameter...
var myElement = document.getElementsByTagName('DIV')[0];
setToBlack(myElement);
function setToBlack(element) {
element.style.backgroundColor = 'black';
}
However I would like to do this were the element is passed without using any parameter and is declared before the dot. This example does not work and I am struggling to get it to work. Any advice will be most appreciated. I am sure this has been asked on stackoverflow before but I am unable to find it with searching since I am unsure of the proper definitions on what this is called.
var myElement = document.getElementsByTagName('DIV')[0];
myElement.setToBlack();
function setToBlack() {
this.style.backgroundColor = 'black';
}