1

The last line of my code is jquery. It works, but I'm trying to find the pure-javascript equivalent

jQuery

var previewFrame = document.getElementById('my_iframe'),
    preview =  previewFrame.contentDocument ||  previewFrame.contentWindow.document;

    preview.open();
    preview.close();

    style = document.createElement( 'style' ); 
    style.type = 'text/css';
    style.id = 'xmain_css1';
    $('#my_iframe').contents().find('head').append(style);

.

This is the closest I could come up with for the LAST LINE (Doesn't work):

preview.head.appendChild(style);

Any thoughts?

Sanya
  • 1,270
  • 5
  • 21
  • 47
  • 1
    try: preview.head.innerHTML += style; (untested) – Lorenzo Marcon Jul 15 '13 at 21:03
  • possible duplicate of [How to append data to div using javascript?](http://stackoverflow.com/questions/5677799/how-to-append-data-to-div-using-javascript) – Gianpaolo Di Nino Jul 15 '13 at 21:05
  • 1
    Seems to work just fine -> http://jsfiddle.net/XhZLD/4/, is the iFrame showing a page from the same domain. – adeneo Jul 15 '13 at 21:08
  • Yes. Both of your codes work well. I think something is messed up in my main project as it is not working - but I too created a fiddle with your code and it works great. I'll have to figure out what I'm doing wrong. Thanks guys! – Sanya Jul 15 '13 at 21:12
  • @Gianps. No. Appending to elements in an iframe is different than appending to a div. – Sanya Jul 15 '13 at 21:14
  • @adeneo. I'm one of the million people who are attempting to make their own jsfiddle - so the iframe will custom html/css/js that the user types into each textarea – Sanya Jul 15 '13 at 21:16

0 Answers0