Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger for span text/html on changed

Is there any event in jQuery or JavaScript that triggered when span tag text/html has been changed ?

Code:

<span class="user-location"> </span>

$('.user-location').change(function () {
    //Not working
});
like image 395
Govind Samrow Avatar asked Aug 30 '16 07:08

Govind Samrow


People also ask

How to change the text of a span element in HTML?

Given an HTML document and the task is to change the text of span element. There are two property used to change the content. HTML DOM textContent Property: This property set/return the text content of the defined node, and all its descendants.

How to add a change event when changing text in Span1?

As a work around, if you really want it to have a change event, then don't asign text to span 1. Instead asign an input variable in jQuery, write a change event to it, and whever ur changing the text of span1 .. instead change the value of your input variable, thus firing change event, like so:

What is a span tag in HTML?

In HTML, the span tag is a generic inline container element. Span tags usually wrap sections of text for styling purposes or for adding attributes to a section of text without creating a new line of content. A span tag is written with an opening and a closing tag, like so: <span> Content goes here </span>

What does textarea onchange get the HTML code to trigger?

What does Textarea Onchange: Get The HTML Code To Trigger A JavaScript Event Now do? Adds an event listener to a <textarea> which executes JavaScript scripting when an onchange event occurs. <form> <textarea onchange="alert ('You just changed the textarea.')" placeholder="Type in this box.


1 Answers

you can use DOMSubtreeModified to track changes on your span element i.e(if text of your span element changes dynamically ).

$('.user-location').on('DOMSubtreeModified',function(){
  alert('changed')
})

check out the followinf link https://jsbin.com/volilewiwi/edit?html,js,output

like image 64
Mohit Arora Avatar answered Sep 16 '22 14:09

Mohit Arora