How can I detect a change inside an <span>
element I need to attach a handler to it but can't succeed.
Here is my html:
<span class="pad-truck-number-position"><?php echo $_SESSION['truckId']; ?></span>
And this is my javascript/jQuery:
<script type="text/javascript">
var changedText = $('.pad-truck-number-position').text();
alert(changedText);
$(changedText).on('change',function() {
alert("changed");
});
</script>
alert(changedText)
does work fine. But when the text inside the span changes it doesn't alert alert("changed");
This is how I change the element:
truckTable.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
var nTds = $('td', this);
var index = $(nTds[0]).text();
$.ajax({
type: "POST",
url : "content/right-up/trucks.php/",
data: { truckid : index },
headers : {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}
}).done(function(response){
$('.pad-truck-number').text(index);
$('.pad-truck-number-position').text(index);
$('#mapContent').load("content/left-up.php");
$('#right-down-tab-truck').tabs('load', 0);
$('#right-down-tab').hide();
$('#right-down-tab-truck').show();
});