tags:

views:

39

answers:

1

Hello,

<td><span id="v">77483.2231</span></td>

When the #v value changes I want to get an pop-up alert

$('#v').change(function() {
    alert("ok");
});

That's my code, its not working though, what could be wrong?

Thanks

Jean

+1  A: 

Sorry, .change() only works with form elements

This event is limited to elements, boxes and elements.

From jQuery Docs

Either do your code where you change the span text elsewhere in the script or set up some kind of listener to watch and see if it changes?

Further explanation of what you're trying to do (and why) would help.

BenWells
@ben whats the way through?
Jean
That all depends on what it is you're trying to do and what you already have. - To start with why does the text change and who makes the change?
BenWells
The text is a change from the db, so when the change is made an alert pops.
Jean
Sorry I missed the last comments on the original post but why can't you run a function on the ajax request callback?
BenWells
@Bean 10K of already existing code needs to be changed
Jean
I still don't think you understand. The answer to your first question is you can't use .change() on a span. Do you call $.ajax to load the content? if so you can add a function in the callback that will notify your set of elements that they've been changed. If magic fairies add content to your site without you knowing you probably need to do something like set a data attribute for the initial content ($('#v').data('org_data',$('#v').text())), then check that with the current content every few second/minutes/hours/weeks. (setInterval('checkStuff()',10000))
BenWells