HTML Articles

Page 118 of 151

How to Add onclick in a Button using javascript?

Eesha Gandhi
Eesha Gandhi
Updated on 15-Mar-2026 12K+ Views

The onclick event generally occurs when the user clicks on an element. It enables the programmer to run a JavaScript function when an element is clicked. This event can be used to validate a form, display warning messages, and much more. This event can be added dynamically to any element using JavaScript. Except for , , , , , , , , , , and , it supports all HTML elements. In HTML, we can use the onclick attribute and associate it with a JavaScript function. For greater flexibility, we can also use JavaScript's addEventListener() method and pass ...

Read More

How to Set Default HTML Form Focus Without JavaScript?

Eesha Gandhi
Eesha Gandhi
Updated on 15-Mar-2026 889 Views

A HTML form is a section of a document that includes controls like text fields, password fields, checkboxes, radio buttons, a submit button, menus, and so on. It allows the user to enter any data like name, email address, password, phone number, and so on that will be sent to the server for processing. HTML forms are required if we want to collect information from site visitors. The syntax for creating a form is given below. --form elements— Example: Form Without Focus Here is an example showing a simple form ...

Read More

How to Trigger a File Download when Clicking an HTML Button or JavaScript?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 49K+ Views

To trigger a file download when clicking an HTML button or JavaScript, is a very common and important part of web page where users can directly download the file they want by clicking a button or link. We will be understanding four different approaches to achieve this. In this article, we are having a button in our HTML document and our task is to trigger a file download when clicking an HTML button or JavaScript. Approaches to trigger file download Here is a list of approaches to trigger a file download when clicking an HTML button or ...

Read More

How to trigger the HTML button after hitting enter button in the textbox using JavaScript?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 6K+ Views

Generally, developers add the submit button to submit the input field's text. However, if they allow users to submit the input value by pressing enter, it improves the UX of the application. Here, we will learn the general way to detect the key press using the key listener event. Afterwards, we can perform any operation whenever the user presses the enter key button. Syntax Users can follow the syntax below to detect whenever the user presses the enter key. input.addEventListener("keypress", function (event) { if (event.keyCode == 13) { ...

Read More

How to Get the Content of an HTML Comment Using JavaScript

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 774 Views

HTML comments are pieces of code that web browsers ignore. They're used to add notes and documentation to HTML code, making it easier to understand and maintain. Comments are written between tags. While browsers ignore comments during rendering, JavaScript can access and extract their content using various string manipulation methods. Syntax HTML comments follow this syntax: Method 1: Using replaceAll() Method The replaceAll() method can remove comment tags to extract the inner content: ...

Read More

How To Change Text Inside All HTML Tags Using JavaScript

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 1K+ Views

In this article, we are going to perform the task of changing text inside all HTML tags using JavaScript. Let's dive into the article to learn more about changing text within all HTML, but first, let's define HTML tags. What are HTML Tags An HTML tag is a segment of markup language used to denote the start and end of an HTML element in an HTML document. HTML tags, which are a component of an HTML element, assist web browsers in turning HTML documents into web pages. For getting better understanding on changing text inside all HTML ...

Read More

How To Modify This JavaScript Code To Grab An Image URL From A JSON File, And Display It In HTML?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 10K+ Views

This can be done by using the JavaScript method JSON.parse() to parse through the JSON file and extract the URL of the desired image. Then, an HTML img tag can be created with a source attribute set to this URL. Finally, this img tag can be appended to an existing HTML element in order to display it on your page. This will require some knowledge of basic JavaScript syntax, as well as familiarity with how JSON is structured and parsed within it. With these skills in hand, you should have no trouble modifying your code to achieve your goal! ...

Read More

Difference Between textContent and innerHTML

Pradeep Kumar
Pradeep Kumar
Updated on 15-Mar-2026 661 Views

There are various methods used in web development to change the text or add additional elements to an HTML element's content. textContent and innerHTML are two frequently used properties for changing an HTML element's content. Although these two properties might appear to be identical, they have distinct behaviors and applications. The textContent property sets or retrieves the text content of an element and all of its descendants without any HTML tags. In contrast, the innerHTML property sets or retrieves an element's HTML content, including all HTML tags and their associated attributes. By adding new elements or modifying existing ones, ...

Read More

How to Hide an HTML Element by Class using JavaScript?

Mrudgandha Kulkarni
Mrudgandha Kulkarni
Updated on 15-Mar-2026 9K+ Views

When working with dynamic web pages, it's often necessary to hide certain HTML elements based on specific conditions or user interactions. One common approach is to assign classes to these elements and then dynamically hide them using JavaScript. This provides a flexible and efficient way to control the visibility of elements without modifying the HTML structure. In this article, we will explore how to hide HTML elements by class using JavaScript. We'll discuss different methods to select elements by class and demonstrate practical techniques for hiding and showing elements dynamically. Methods for Selecting Elements by Class JavaScript ...

Read More

How to Convert Characters to ASCII Code using JavaScript?

Jaisshree
Jaisshree
Updated on 15-Mar-2026 3K+ Views

ASCII stands for American Standard Code for Information Interchange, which is a method used for encoding characters by assigning them to a specific numerical value. The numerical values thus assigned are known as ASCII codes and are extensively utilized in computer systems to represent various characters including letters, numbers, punctuation marks, and special control characters. Using charCodeAt() Method The charCodeAt() method returns the ASCII code of the character at a specified index in a string. This is the most common method for ASCII conversion. Syntax string.charCodeAt(index) Example ...

Read More
Showing 1171–1180 of 1,509 articles
« Prev 1 116 117 118 119 120 151 Next »
Advertisements