I'm making a shorthand function for a build in JavaScript function:
function editById(getId) {
document.getElementById(getId);
}
then I tried using it in my script.js:
function run() {
document.editById("test").style.color="blue";
}
then my HTML:
<p id="test">TestTestestestse</p>
<input type="button" onclick="run()" value="Change text color">
This doesn't work with editById, but it does getElementById...
ABOVE SOLVED
Adding onto that:
Now this doesn't work:
shortHand.js
// Long term document functions
document.editById = function (find) { return document.getElementById(find); }
document.editByClass = function (find2) { return document.getElementsByClassName(find2); }
document.editByTag = function (find3) { return document.getElementsByTagName(find3); }
script.js
function run() {
document.editById("test").style.color="blue";
}
function run2() {
document.editByClass("test").style.color="blue";
}
function run3() {
document.editByTag("h1").style.color="blue";
}
HTML
<p id="test">TestTestestestse</p>
<p class="test">TestTestestestse222</p>
<h1>TestTestestestse368585475</h1>
<input type="button" onclick="run()" value="Change text color">
<input type="button" onclick="run2()" value="Change text color">
<input type="button" onclick="run3()" value="Change text color">
document.editById?