Jitender
Jitender

Reputation: 7971

Jquery's .contents() not working

I am using jQuery .contents() method to change class under iframe but it is not wokring. When i am giving direct in iframe source then it is working fine but when i generating path it is not working

$('.viewMe').click(function (){
    var url= 'viewpage.html'
    $('#myframe').attr('src',url).animate({height:1000},1000, 
        function (){$('.Close').fadeIn(1500)});
    $('body').height($(window).height()).css('overflow','hidden');

    var $c = $('#myframe').contents();
    $c.find('.inner-wp').css('margin','0')
});

Upvotes: 2

Views: 11819

Answers (2)

Edgardo Genini
Edgardo Genini

Reputation: 663

from https://forum.jquery.com/topic/not-working-content-method-of-iframe

"it only works when both the iframe and the page come from the same domain. And it only works after the iframe is actually loaded."

Upvotes: 1

bugwheels94
bugwheels94

Reputation: 31920

You have to call it on iframe load event like this:

$("#myframe").load(function() {
  var $c = $('#myframe').contents();
  $c.find('.inner-wp').css('margin', '0');
});

Upvotes: 3

Related Questions