0

In my page, there is a iframe loads, I just want to find the element after it loads, so that I used this function:

$("body").on("DOMNodeInserted", ".ssueContentIframe", function() {
  $(this).css('border', '1px solid red'); //works
  update();
});

After the Iframe loaded, I would like to add a event Listener to one of my element, so I would like to listen as well for that I am calling a function as update like above, but I am not getting the result.

What is the correct way to use the DOMNodeInserted for Iframe contents? here is my try on update function:

    var update = function(){

        $(".ssueContentIframe").contents().on("DOMNodeInserted", '.ui-grid-selection-row-header-buttons', function(){
            //above contents load in for loop, after loop nothing added
            $(this).css('border', '1px solid red');//not works
        });

    };

or what is the correct way, is there any plugin otherwise? Require you kind help here!

3gwebtrain
  • 14,640
  • 25
  • 121
  • 247

1 Answers1

0

Note, Mutation Events are deprecated. You should probably utilize MutationObserver, see call function on change of value inside <p> tag .

To use existing javascript at Question, since you have already attached the event to body element, all nodes which are inserted at <body> element should be accessible at the event handler using event.originalEvent.originalTarget or event.originalEvent.explicitOriginalTarget. Calling update() to attach another DOMNodeInserted event at elements withing <body> of iframe document is not necessary.

$("body").on("DOMNodeInserted", ".ssueContentIframe", function(event) {
  $(this).css('border', '1px solid red'); //works
  console.log(event.originalEvent.originalTarget); // inserted node
});
Community
  • 1
  • 1
guest271314
  • 1
  • 15
  • 104
  • 177
  • tried, Not working. contents are inserted inside the iframe by loop iteratror – 3gwebtrain Sep 29 '16 at 05:10
  • What is issue with using `javascript` at Question? Note, `Mutation Events` are deprecated. `MutationObserver` should probably be used. – guest271314 Sep 29 '16 at 05:26
  • I don't have knowledge with `MutationObserve` - can you update your answer with same? - very glad to you – 3gwebtrain Sep 29 '16 at 05:29
  • @3gwebtrain If update Answer to `MutationObserver`, Question would be duplicate of link at Answer. Which is probably best solution. You can check where the mutation occurred using working `javascript` at Question by checking `event.originalEvent.explicitOriginalTarget`. – guest271314 Sep 29 '16 at 05:32