javascript - Mutation Summary Library: How to append html elements to added elements -
i'm using mutation summary library observe when particular type of elements have been added , append html element each of them:
var observer = new mutationsummary({ callback: thenextpageloaded, queries: [{ element: "li.sweet" }] }); function thenextpageloaded(summaries) { var sc = summaries[0], sc_length = sc.added.length, btn = $('<button>', { class: 'my_btn', text: 'please work!' }); sc.added.foreach(function(newel) { newel.appendchild(btn); console.log(typeof(newel)); //newel's type 'object' }); }
code above not working. i'm not sure can utilize appendchild
on object. help appreciated!
your problem mixing "bare" dom elements mutation summary response , jquery elements. pure dom appendchild
not understand jquery-wrapped btn
.
so, need create them both same type:
$(newel).append(btn); // jquery newel.appendchild(btn.get(0)); // pure dom
either works, first 1 more idiomatic.
javascript jquery google-chrome-extension mutation-observers
No comments:
Post a Comment