Here I have a simple button with class .change
in my HTML.
Now when I click on the button and then observe the Chrome console I get the output as mouse event and the text written on button ("Click Me!"), which is excepted.
To my surprise when I navigate the mouse event in the google console then I see e.target.innerText
was set to "HELLO". How is it possible I have first console log the event then changed the innerText
to "HELLO" in last line.
Also when I use debugger breakpoint the output was expected. Without using debugger the innerText
attribute in the mouseevent (console log in 1st line of eventhandler) is showing "HELLO".
let btn = document.querySelector('.change');
btn.addEventListener ("click", (e) => {
console.log(e);
const text = e.target.innerText;
console.log(text);
e.target.innerText = "HELLO";
});
HTML :-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>A button</title>
</head>
<body>
<button type="button" class="change">Click me!</button>
<script src="/practice/prac.js"></script>
</body>
</html>