7

I'm trying to append a css file to an iframe that is created on a page from a global script. I can access part of it, but for some reason I can't append to the head. It's not throwing errors either, which is frustrating.

<script type="text/javascript">
$(document).ready(function() {                   
  $('#outline_text_ifr')
    .contents()
    .find('head')
    .append('<link type="text/css" rel="stylesheet" href="/include/outline.css" media="all" />');
});
</script>
Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
Micharch54
  • 576
  • 1
  • 7
  • 15

1 Answers1

14
var $head = $("#IFrame").contents().find("head"); 
var url = "Styles/styles.css";
$head.append($("<link/>", { rel: "stylesheet", href: url, type: "text/css" } ));

or

        $('#IFrame').contents().find('#div1').css({
            color: 'purple'
        });
Rami Sarieddine
  • 5,396
  • 35
  • 41