0

I would like to make a script that, when the text of a certain paragraph change, start a certain function, I tried the follow but i don't think the method change() works for a paragraph

$("#myParagraph").change(function(){......})
Nurdin
  • 23,382
  • 43
  • 130
  • 308
thestral
  • 971
  • 1
  • 6
  • 12

1 Answers1

0

You would wrap that tag or "paragraph" in a container, and bind that container to a event possibly. You could also look into using the length of the "text" property. During this triggered event, check that the state is different. I can write an example if you need one. One place to look at is the

//global variable. Store in hidden field if you would like.
var currentVal = $('element').text();


$('element').bind("DOMSubtreeModified",function(){
  var newVal = $(element).text();
  if(currentVal != newVal)
  {
       //call function here.  
  }
});

This is basic and very simple, but to give you the idea.

Casey ScriptFu Pharr
  • 1,672
  • 1
  • 16
  • 36
  • Its not my website, i'm trying to make an extension, to be more clear , the paragraph show a message every 5 minutes like that "aroud 10 min left" "aroud 5 min left" , i would like to start a countdown of 5 minutes when it changes – thestral Mar 20 '15 at 19:28
  • Thanks for the help, can you please write me the part of the code independent from my function? I mean the part that checks if the value has changed – thestral Mar 20 '15 at 19:33