Scroll Down
The javascript Document method getElementById(String) is a fast way of returning an HTML Element Object representing the element that matches the specified idstring parameter.
var element = getElementById("html-tag-id-attribute");
var element = getElementById(id);
The id parameter is a string with the html element id attribute to be searched.
HTML Element Object or NULL.
All browsers.
Consider the following HTML setup. The goal of this test is to select the section‘s first div element
<section>
<div class="class-selector-0 general" id="id-selector-0"></div>
<div class="class-selector-1 general" id="id-selector-1"></div>
<div class="class-selector-2 general" id="id-selector-2"></div>
</section>
var element = document.getElementById("id-selector-0");
var element = document.getElementsByClassName("class-selector-0")[0];
var element = document.querySelector('#id-selector-0');
var element = document.getElementsByTagName("div")[0];
var element = $("#id-selector-0").get(0);
var element = $("#id-selector-0").get(0);
var element = document.querySelector('.class-selector-0');
var element = document.querySelectorAll('div')[0];
var element = document.querySelectorAll('.general')[0];
var element = document.querySelector('div:nth-child(0)');
var element = document.querySelector('section > div:nth-child(0)');