How to useaddEventListener() method in Javascript
In javascript with the help of the addEventListener() method, we can attach the input javascript event to the textarea.
Example: In this example, we are using the above-explained approach.
HTML
<!DOCTYPE html> < html lang = "en" > < head > < style > h1 { text-align: center; } .abc { display: flex; justify-content: center; text-align: center; } </ style > </ head > < body > < h1 style = "color:green;" > w3wiki </ h1 > < div class = "abc" > < input id = "gfg" > </ div > < script > document.getElementById("gfg") .addEventListener("input", (event) => alert("Changed!")); </ script > </ body > </ html > |
Output:
How to detect If textbox content has changed using JavaScript ?
The task is to detect the changes in the textbox content with JavaScript. Whenever a user writes or types something in the input text box we have to detect that event by the use of some methods present in JavaScript.
There are some common approaches that are discussed below:
Table of Content
- Using onchange event
- Using onpropertychange event
- Using addEventListener() method