I wonder if it’s possible in jQuery/JS:
If “foobar” is removed or gone from the HTML code
<div id="foo">
<div id="line1">...</div>
<div id="line2">foobar</div>
</div>
I’d like to automatically add “new”
<div id="foo">
<div id="line1">...</div>
<div id="line2">new</div>
</div>
I’d like to have “new” displayed when someone deleted “foobar” from #line2. It’s for attribution purposes.
If you make the text the value of an input you can bind to it’s
changeevent:Here is a demo: http://jsfiddle.net/u9Twu/
Note that if you want to programatically change the value of the input you have to manually call
.trigger('change')on the input after you change it’s value for thechangeevent handler to run.Also note that
.on()is new in jQuery 1.7 and in this case is the same as.bind().UPDATE
Here is a demo: http://jsfiddle.net/u9Twu/1/