Mutationobserver Monitoring DOM element structure change and attribute change instances

Source: Internet
Author: User

1 varmutationobserver = window. Mutationobserver | | Window. Webkitmutationobserver | | Window. Mozmutationobserver;//Browser compatible2 varConfig = {attributes:true, Childlist:true}//Configuration Objects3$ ("DOM element to listen for"). each (function(){4    var_this = $ ( This);5    varObserver =NewMutationobserver (function(mutations) {//Constructor Callback6Mutations.foreach (function(record) {7          if(Record.type = = "Attributes") {//Listening Properties8           //Do any code9          }Ten          if(Record.type = = ' Childlist ') {//The monitoring structure has changed . One               //Do any code A          } -       }); -    }); theObserver.observe (_this[0], config); -});

Configuration Object Config Property

    • Childlist: Changes in child elements
    • Attributes: Changes in attributes
    • Characterdata: Changes in node content or node text
    • Subtree: Changes to all subordinate nodes (including child nodes and child nodes)
    • Attributefilter: Monitoring development properties [Attrname]

Note: Subtree can not be used alone, and other properties should be combined;


Stop monitoring observation
Observer.disconnect ();

Clear History Listening record

Observer.takerecord

 

Record returns the properties of an object
    • Type: Types of observed changes (attribute, Characterdata, or childlist).
    • Target: The DOM object that has changed.
    • Addednodes: New DOM object.
    • Removenodes: The deleted DOM object.
    • PreviousSibling: The previous sibling of the DOM object, or null if none.
    • NextSibling: The next sibling of the DOM object, if not, returns NULL.
    • AttributeName: The property in which the change occurred. If Attributefilter is set, only pre-specified properties are returned.
    • OldValue: The value before the change. This property is only valid for attribute and characterdata changes, and returns null if a childlist change occurs.

Mutationobserver Monitoring DOM element structure change and attribute change instances

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.