Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use onchange in a div

Is it possible to use onchange event in a <div>?

Because my <div> changes its text inside.

Can I do something like this?

<div id="name" onchange="calculateTotal();"></div> 
like image 303
Rafael Morais dos Santos Avatar asked Jul 13 '11 08:07

Rafael Morais dos Santos


1 Answers

You can use 'onInput' instead of 'onChange'.

<div className="inputDiv" contenteditable="true" onInput={(e) => { console.log(e.currentTarget.textContent) }} />

Check the console log with Chrome Developer Tools (F12):

enter image description here

References: https://stackoverflow.com/a/52614631/8706661

like image 59
HellJosun Avatar answered Oct 19 '22 22:10

HellJosun