0

I am trying to get a function to trigger if the text inside of a span class changes. As you can see I want to just display an alert box when the span class with the class name ddlabel is changed.

Ideally, I then want to check to if the text of the span matches a certain value.

$(function() {

    $('span.ddlabel').on('DOMSubtreeModified',function() {
        alert("run");
    });
    
});

Here is the code for the span class I am trying to access to check if the text has changed and to grab the text value of.

<span class="ddTitleText " id="selectbasic_0_0_3_2_title" data-trn-key="Choose an option...">
    <span class="ddlabel trn" data-trn-key="2 ">2</span>
    <span class="description trn" data-trn-key=" "></span>
</span>

enter image description here

isherwood
  • 58,414
  • 16
  • 114
  • 157
Matt
  • 3
  • 2
  • That event [has been deprecated](https://developer.mozilla.org/en-US/docs/Archive/Events/DOMSubtreeModified). Why aren't you using a callback on whatever's modifying the text? – isherwood Feb 10 '21 at 18:57
  • I'm not aware of what's modifying the text as I'm trying to work with code written by someone else so I'm struggling to get my head round it. – Matt Feb 10 '21 at 19:07
  • So I need to use onDomChange(function(){? – Matt Feb 10 '21 at 19:15

0 Answers0