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
});
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.
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:
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 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With