Sun Rhythms
Sun Rhythms

Reputation: 55

How to add iframe to a div with jquery

I found this code in the accepted answer here... which loads an iframe into a specific area via a button click...

<a href="#" onclick="setIframe(this,'http://www.stackoverflow.co.uk')" >Set the Iframe up</a>

function setIframe(element,location){
    var theIframe = document.createElement("iframe");
    theIframe.src = location;
   element.appendChild(theIframe);
}

how do I change this so that it allows me to style the height width and scrolling?

Upvotes: 3

Views: 4060

Answers (2)

Hanlet Esca&#241;o
Hanlet Esca&#241;o

Reputation: 17370

This is not jQuery, but pure Javascript:

function setIframe(element,location){
    var theIframe = document.createElement("iframe");
    theIframe.src = location;
    theIframe.setAttribute("weight", "500");
    theIframe.setAttribute("width", "500");
    theIframe.setAttribute("scrolling", "yes");
    element.appendChild(theIframe);
}

This is not part of your question, but here is how you toggle a div with jQuery:

Markup:

<input type="button" value="Toggle Div"  id="btnToggle"/>

    <div id="randomContent">
        This is random Content.
        <br />
        This is random Content.
        <br />
        This is random Content.
        <br />
        This is random Content.
        <br />
        This is random Content.
        <br />
        This is random Content.
        <br />
    </div>

jQuery:

    $(document).ready(function () {
        $("#btnToggle").bind("click", function () {
            $("#randomContent").toggle();
        });
    });

Upvotes: 2

Talha Akbar
Talha Akbar

Reputation: 10030

theIframe.style.*

Any Property Which You want to style.

Upvotes: 2

Related Questions