Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to fire event on label text change

I'm trying to fire a function when the label text changes. This is my code

$("#frameItemCode").change(function (e) {
    alert("Changed");
});

#frameItemCode is my label id, but the event isn't firing. I have tried examples given before but they hasn't helped me.This is my html

<div class="input-group">
  <span class="input-group-addon" @*style="width: 120px;"*@>Item Group</span>
  <label class="input-group-addon" @*style="width: 120px;"*@ id="frameGroupCode"></label>
  <input class="form-control" type="text" id="frameGroupName" style="">
</div>
like image 464
Saranga Avatar asked Dec 24 '14 10:12

Saranga


People also ask

How do I change a dynamic label?

To dynamically update the Label widget, we can use either config(**options) or an inline configuration method such as for updating the text, we can use Label["text"]=text; for removing the label widget, we can use pack_forget() method.

How do I change labels in HTML?

Use the textContent property to change the text of a label element, e.g. label. textContent = 'Replacement label text' . The textContent property will set the text of the label to the provided string, replacing any of the existing content. Here is the HTML for the examples in this article.


1 Answers

Depending on which browsers you need to support, you can use MutationObserver:

var observer = new MutationObserver(
    function (mutations) {
        alert('Label was changed!');
    }
);

observer.observe(document.querySelector('#frameGroupCode'), { childList: true });

Example jsFiddle

like image 193
Phylogenesis Avatar answered Sep 17 '22 16:09

Phylogenesis