mutation-events

Feature-detect: mutation-event availability in JavaScript?

断了今生、忘了曾经 提交于 2019-12-05 03:33:16
How can my JavaScript detect if an event is available? I'm aware of some great event-compatibility tables , but I need to use feature detection, not browser-sniffing plus a lookup table. Specifically, my JS makes great use of the DOM mutation events ( DOMNodeInserted and DOMSubtreeModified ) -- which work great in all browsers except (of course) Internet Explorer. So, how would I detect if a browser supports DOMNodeInserted ? If you just want to check if the browser supports mutation events in general, you can use this simple test: var hasMutationEvents = ("MutationEvent" in window); Here are

Using DOMSubtreeModified mutation event. in jQuery

送分小仙女□ 提交于 2019-12-04 00:20:50
问题 I have used the following jQuery code on my page and everything works fine on chrome.But when I open up the respective page in firefox I get the Unresponsive Script Error. I know as per DOM3 specification the mutation events have been deprecated. But Still if anyone could help me out here, I'll be obliged. jQuery('#term').on("DOMSubtreeModified",function(){ $("#term > .click-slide").click(function(){ $(this).siblings().slideToggle(); }); }); Respective HTML is: <div class="btn-slide" id="term

How do I play a sound when an element changes, like SO Chat does?

夙愿已清 提交于 2019-12-03 12:01:59
I want a sound to play when an element changes on a page. I know how to do this, but I can't get it to play only on the first change , and don't do it later, until the user focuses the window (tab) and blurs it again. My current code: var notif = new Audio('http://cycle1500.com/sounds/infbego.wav'); if (window.innerHeight === window.outerHeight) { $(window).bind('DOMNodeInserted', function() { notif.play(); }); } Use a variable to represent whether the sound should be played or not. var shouldPlayAlertSound = true, notif = new Audio('http://cycle1500.com/sounds/infbego.wav'); if (window

Are DOM Mutation Observers slower than DOM Mutation Events?

做~自己de王妃 提交于 2019-12-03 07:42:12
问题 The following code utilize DOM Mutation Event DOMNodeInserted to detect the existence of the body element and wrap its innerHTML into a wrapper. <!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script> function DOMmanipulation() { if (document.body) { document.removeEventListener('DOMNodeInserted', DOMmanipulation); // DOM manipulation start document.body.innerHTML = '<div class="wrapper">' + document.body

Detecting DOM change events

我与影子孤独终老i 提交于 2019-12-02 04:17:39
问题 Is there a way to detect DOM change events? whether it be text replacement, moving a node, removing or adding a new node, etc. 回答1: I think what you're looking for is DOMSubtreeModified Edit: upon further inspection this and other MutationEvents have been deprecated by the W3C but there doesn't appear to be a replacement until DOM Level 4 See: "Why is the DOMSubtreeModified event deprecated in DOM level 3?" Long story short, DOMSubtreeModified will still work and there is no reasonable

Detecting DOM change events

∥☆過路亽.° 提交于 2019-12-02 02:29:43
Is there a way to detect DOM change events? whether it be text replacement, moving a node, removing or adding a new node, etc. Ansel Santosa I think what you're looking for is DOMSubtreeModified Edit: upon further inspection this and other MutationEvents have been deprecated by the W3C but there doesn't appear to be a replacement until DOM Level 4 See: "Why is the DOMSubtreeModified event deprecated in DOM level 3?" Long story short, DOMSubtreeModified will still work and there is no reasonable alternative implemented across stable browsers. 来源: https://stackoverflow.com/questions/8733306

Using DOMSubtreeModified mutation event. in jQuery

╄→гoц情女王★ 提交于 2019-12-01 03:37:29
I have used the following jQuery code on my page and everything works fine on chrome.But when I open up the respective page in firefox I get the Unresponsive Script Error. I know as per DOM3 specification the mutation events have been deprecated. But Still if anyone could help me out here, I'll be obliged. jQuery('#term').on("DOMSubtreeModified",function(){ $("#term > .click-slide").click(function(){ $(this).siblings().slideToggle(); }); }); Respective HTML is: <div class="btn-slide" id="term"> <div class="click-slide"> <button>Search Terms </button> </div> <div class="btn-box"> <label><span

onpropertychange for a textbox in Firefox?

折月煮酒 提交于 2019-11-30 16:25:32
How to handle the onpropertychange for a textbox in Firefox using JavaScript? Below is an example: var headerBGColorTextBox = document.getElementById('<%= tbHeaderBGColor.ClientID %>'); if (headerBGColorTextBox != null) { headerBGColorTextBox.pluggedElement = document.getElementById('<%= trHeaderBG.ClientID %>'); headerBGColorTextBox.onpropertychange = function() { alert('function called'); if (event.propertyName == 'style.backgroundColor' && event.srcElement.pluggedElement != null) alert(event.propertyName); event.srcElement.pluggedElement.style.backgroundColor = event.srcElement.style

onpropertychange for a textbox in Firefox?

烈酒焚心 提交于 2019-11-30 16:06:30
问题 How to handle the onpropertychange for a textbox in Firefox using JavaScript? Below is an example: var headerBGColorTextBox = document.getElementById('<%= tbHeaderBGColor.ClientID %>'); if (headerBGColorTextBox != null) { headerBGColorTextBox.pluggedElement = document.getElementById('<%= trHeaderBG.ClientID %>'); headerBGColorTextBox.onpropertychange = function() { alert('function called'); if (event.propertyName == 'style.backgroundColor' && event.srcElement.pluggedElement != null) alert

Preferred way of modifying elements that have yet to be created (besides events)

随声附和 提交于 2019-11-29 20:46:13
There are a lot of questions about binding future manipulations to non-existent elements that all end up answered with live /delegate . I am wondering how to run an arbitrary callback (to add a class or trigger a plugin, for example) to all existing elements that match a selector and all future elements that match that same selector that are yet to be created. It seems that the main functionality of the livequery plugin made it into the core but the other part, attaching arbitrary callbacks got lost along the way somehow. Another common answer is event delegation but what if one doesn't have