Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
61
rated 0 times [  64] [ 3]  / answers: 1 / hits: 67420  / 10 Years ago, thu, october 9, 2014, 12:00:00

I just want to know how can I display an iframe on button click



Here is my code:





function postYourAdd () {
var iframe = $(#forPostyouradd);
iframe.attr(src, iframe.data(src));
}

<button id=postYourAdd onclick=postYourAdd()>Button</button>
<iframe id=forPostyouradd data-src=http://www.w3schools.com src=about:blank width=200 height=200 style=background:#ffffff></iframe>




More From » jquery

 Answers
13

At least in the Snippet you provided, you forgot to add a reference to JQuery. See it working now:





function postYourAdd () {
var iframe = $(#forPostyouradd);
iframe.attr(src, iframe.data(src));
}

<script src=https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js></script>
<button id=postYourAdd onclick=postYourAdd()>OPEN</button>
<iframe id=forPostyouradd data-src=http://www.w3schools.com src=about:blank width=500 height=200 style=background:#ffffff></iframe>




[#69178] Tuesday, October 7, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brynnleslis

Total Points: 425
Total Questions: 100
Total Answers: 115

Location: Wallis and Futuna
Member since Tue, Mar 30, 2021
3 Years ago
;