On Apr 24, 2:03 am, Yozefff <
yoze...@gmail.com> wrote:
> hmm no luck :(
>
> <a href='javascript:test()'>test</a>
>
> <div id='myDiv'></div>
>
> <script>
>
> function test(){
> $("myDiv").update("yo");
> }
>
> $("myDiv").observe("DOMCharacterDataChanged",function(evt){
> alert("sup");
>
> });
>
> The domcharacdatachanged event just won't fire (FF3)
The mutation events are listed at the reference I provided,
DOMCharacterDataChanged isn't one of them.
You should test for support before attempting to use them as
attempting to set an unsupported event is supposed to throw an
exception. The official way to detect support is using hasFeature,
but that is insufficient as there is no allowance for partial
implementation (and browsers lie anyway), e.g.:
document.implementation.hasFeature('MutationEvents', '2.0')
shows false in Firefox even though some mutation events are supported
That is the correct response according to the DOM 2 Events spec as it
should only show true if *all* relevant events are supported, but it's
pretty useless for finding out bits are supported and what aren't.
IE shows false for Events 2.0, so there's no point even trying testing
for MutationEvents as support for Events is a prerequisite. The only
reliable strategy I have found for detection is to use try..catch and
see what happens. If an error is thrown, the event isn't supported.
E.g. to test if you can create a mutation event:
window.onload = function () {
var eventType = 'DOMCharacterDataModified';
var el = document.createElement('div');
// Test createEvent
try {
el.createEvent(eventType);
alert('createEvent ' + eventType + '\nOK');
} catch (e) {
alert('createEvent ' + eventType + '\nNot supported.');
}
// Test addEventListener
try {
el.addEventListener(eventType, sayHi2, true);
alert('addEventListener ' + eventType + '\n OK');
} catch (e) {
alert('addEventListener ' + eventType + '\nNot supported.');
}
}
The above shows that DOMCharacterDataModified is not supported by
createEvent, but is OK with addEventListener. You need to test after
the onload event has fired else it will return false, even in Firefox.
--
Rob