Created
February 16, 2024 06:28
-
-
Save dfkaye/f2ff9309ab9dfe47995cfd0b041e062d to your computer and use it in GitHub Desktop.
many ways to access forms and elements in the DOM
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
// 15 February 2024 | |
// many ways to access forms and elements in the DOM | |
var input = document.createElement("input"); | |
input.name = "E"; | |
var form = document.createElement("form"); | |
form.name = "F"; | |
form.appendChild(input); | |
document.body.appendChild(form); | |
console.warn(document.forms.F.elements.E.outerHTML); | |
console.log(document.forms["F"].elements.E.outerHTML); | |
console.warn(document.forms.F["E"].outerHTML); | |
console.log(document.forms["F"]["E"].outerHTML); | |
console.warn(document.forms[0].elements[0].outerHTML); | |
console.log(document.querySelector("form").elements.E.outerHTML); | |
console.warn(document.querySelector("form[name=F]").querySelector("input").outerHTML); | |
console.log(document.querySelector("input[name=E]").outerHTML); | |
// should see this and only this output several times | |
// <input name="E"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment