This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Replace the inline styles: | |
for (div of document.getElementsByTagName("div")) { | |
div.style.cssText = "font-size: 3rem" | |
} | |
// Clear out all inline styles: | |
for (div of document.getElementsByTagName("div")) { | |
div.style.cssText = "" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// As a one-liner: | |
for (div of document.getElementsByTagName("div")) { | |
div.style.fontSize = "3rem" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Apply CSS styles to all of the selected <div> elements | |
for (div of allDivs) { | |
div.style.fontSize = "3rem" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Select all the <div> elements on the current page | |
const allDivs = document.getElementsByTagName("div") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Select all <div> elements on the page | |
const divs = document.getElementsByTagName("div") | |
// Apply CSS styles to the selected <div> elements | |
for (div of divs) { | |
div.style.border = "3px solid orange" | |
} | |
// As a one-liner: | |
for (div of document.getElementsByTagName("div")) { div.style.border = "3px solid orange" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load jQuery, equivalent to having the <script> tag on the page | |
// <script src="https://code.jquery.com/jquery-3.5.0.js"></script> | |
const loadScript = async (url) => { | |
const response = await fetch(url) | |
const script = await response.text() | |
eval(script) // or Function(script) | |
} | |
const scriptUrl = "https://code.jquery.com/jquery-3.5.0.js" | |
loadScript(scriptUrl) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://code.jquery.com/jquery-3.5.0.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.getScript("script.js") // Load a script using jQuery |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <script src="https://code.jquery.com/jquery-3.5.0.js"></script> | |
const loadScript = async (url) => { | |
const response = await fetch(url) | |
const script = await response.text() | |
Function(script) | |
} | |
const scriptUrl = "https://code.jquery.com/jquery-3.5.0.js" | |
loadScript(scriptUrl) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <script src="https://code.jquery.com/jquery-3.5.0.js"></script> | |
fetch("https://code.jquery.com/jquery-3.5.0.js") | |
.then((response) => response.text()) | |
.then((text) => eval(text)) | |
.then(() => { | |
/* Use jQuery */ $("div").css("border", "3px dotted orange") | |
}) |