What are the different ways an HTML element can be accessed in a JavaScript code?

Here is the list of ways an HTML element can be accessed in a Javascript code:

getElementById(‘id_name’): // Fetches an element by its ID name
getElementsByClass(‘class_name’): // Fetches all the elements that have the given classname.
getElementsByTagName(‘tag_name’): // Fetches all the elements that have the given tag name.
querySelector(): // This function takes css style selector and returns the first selected element.

Author: Mahesh

Technical Lead with 10 plus years of experience in developing web applications using Java/J2EE and web technologies. Strong in design and integration problem solving skills. Ability to learn, unlearn and relearn with strong written and verbal communications.