Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

283
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda