---
title: "How to find the html elements by using JavaScript?"  
description: "How to find the html elements by using JavaScript?"  
author: "Ravi Vishwakarma"  
published: 2021-07-19  
canonical: https://answers.mindstick.com/qa/93760/how-to-find-the-html-elements-by-using-javascript  
category: "web application"  
tags: ["javascript", "web application development", "web development"]  
reading_time: 1 minute  

---

# How to find the html elements by using JavaScript?

How to find the [html](https://www.mindstick.com/articles/12368/why-are-html-themes-the-first-selection-of-designers) [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements) by using [JavaScript](https://www.mindstick.com/articles/1530/design-a-simple-stylish-calculator-using-html-css-and-javascript)?

## Answers

### Answer by Ethan Karla

In JavaScript has basically four method for finding the html elements. 1. document.getElementById(id-name) 2. document.getElementsByClassName(class-name) 3. document.getElementsByTagName(tag-name); 4. d.getElementsByName(name-attribute name); Example

```
<!DOCTYPE html>
<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
    <meta charset='utf-8' />
    <title></title>
</head>
<body>
    <p id='p2'></p>
    <p class='p3'></p>
    <p ></p>
    <p name='p1'></p>
    <script>
        document.getElementById('p2').innerHTML = 'this is id selector';
        var cls = document.getElementsByClassName('p3');
        cls[0].innerHTML = 'class selector';
        var tags = document.getElementsByTagName('p');
        tags[2].innerHTML = ' this is tag name selector';
        var names = document.getElementsByName('p1')[0];
        names.innerHTML = 'this is name selector';
    </script>
</body>
</html>
```

\


---

Original Source: https://answers.mindstick.com/qa/93760/how-to-find-the-html-elements-by-using-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
