Answer the question
In order to leave comments, you need to log in
What is the best way to access an element by id?
There are three options for addressing:
1) The old fashioned way
2) Symbolic and economicaldocument.getElementById('КакойТоАйДи').метод;
'use strict'; // Включаем прогрессивизм
let ID=t=>document.getElementById(t); // Декоратор дефолтного сатанинского синтаксиса
...
ID('КакойТоАйДи').метод; // собсна, обращение к элементу
КакойТоАйДи.метод;
Answer the question
In order to leave comments, you need to log in
const $ = selector => document.querySelectorAll(selector)
$('#hello .world').forEach(...)
const $ = selector => Array.from(document.querySelectorAll(selector))
if there is only one such id in the document then:
getElementById
or just call directly:
id.remove()
the browser automatically creates the id variable in the global scope
if there are several such id then:
querySelectorAll( '#' + id)
and yes, there can be several id - it's not forbidden and sometimes it's convenient
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question