When we made the initButton it was originally attached to a wrapper, and looked like this.
function initButton(selector) {
var wrapper = document.querySelector(selector);
var button = wrapper.querySelector(".playButton");
wrapper.addEventListener("click", initialOverlayClickHandler);
}
initButton(".wrape");
}());
But what if I wanted to use the initButton on a code that has no wrapper?
Using this as an example:
If I were to put the initButton on this code:
var playButton = document.querySelector(".wrapf");
playButton.addEventListener("click", playButtonClickHandler);
}());
That would become this:
function initButton(selector) {
var wrapper = document.querySelector(selector);
var button = wrapper.querySelector(".playButton");
wrapper.addEventListener("click", playButtonClickHandler);
}
initButton(".wrapf");
}())
But there’s no wrapper on that button.
So these lines would change from “wrapper” to “button”
var button = document.querySelector(selector);
button.addEventListener("click", playButtonClickHandler);
But then, what would this line become?
wrapper would become what instead?
var button = wrapper.querySelector(".playButton");
If I change it to document it says it’s already defined
https://jsfiddle.net/bwa3os2v/244/
https://i.imgur.com/7CRZAwn.png
function initButton(selector) {
var button = document.querySelector(selector);
var button = document.querySelector(".playButton");
button.addEventListener("click", playButtonClickHandler);
}
initButton(".wrapf");
}())
Would I delete and remove this line of code from it?
var button = document.querySelector(selector);
But if I do that I would need to change (selector) to a different name and (button) won’t work on there because it says it’s already defined.
function initButton(selector) {
https://i.imgur.com/fo5Jr10.png
And keep this one?
var button = document.querySelector(".playButton");
Or would both of these lines stay in the code and I would do something else?
var button = document.querySelector(selector);
var button = document.querySelector(".playButton");
I can keep this line removed, deleted from the code and it works. or would that line stay in the code?
https://jsfiddle.net/bwa3os2v/251/
var button = document.querySelector(".playButton");
function initButton(selector) {
var button = document.querySelector(selector);
button.addEventListener("click", playButtonClickHandler);
}
initButton(".wrapf");
}())