Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

281
Views
How to activate an event with on() method when the value of a div tag is changed?

I am currently writing HTML and JS code in the following form, but when I put a new value in the div tag value, the event does not happen.

the Javascript code is

$('#CdText').on('input', function () {
    $('#CdText').innerHTML = concat($('#CdText').innerHTML, 'test');
});

HTML is

<div id="CdText" class="ui-state-highlight" contenteditable="true">1234</div>

The above code does not work.
However it works

$('#appInput').on('input', function () {
   $('#appInput').val(concat($('#appInput').val(), 'test'));
});

because HTML is

<input id="appInput" class="form-control ap-input">
  <div>1234</div>
</input>

By the way, changing $('#CdText').on('input', function () { as follows did not work.
$('#CdText').on('div', function () {
$('#CdText').on('change', function () {
$('#CdText').on('change', 'div', function () {

I hope I'm doing something wrong with Jquery's use of the on() method, but as of yet I haven't found what's wrong.

If you know how to write an event to be triggered every time something is entered into a div like the above, please let me know.

By the way, $('#CdText').on('input', function () { is properly contained in $(function () {}).
css of CdText div tag is inline-block. so it can write as input.

Thank you for reading.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use the contenteditable attribute while listening with .on('input'), however .innerHTML is made for vanilla JS, for jQuery you should use .html().

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!