Reputation: 37
Been trying to make a button which opens a div containing another html page. I had the button working but the main page was opening with the div shown already, I needed it hidden. After messing it all up I'm stuck on this. The button doesn't work.
html
<p>Press the button</p>
<button id="button1" onClick="show()">Show / Hide</button>
<div id="Ahover">
<object type="text/html" data="http://validator.w3.org/"></object>
</div>
css
#Ahover {
display:none;
overflow: hidden;
border:1px ridge blue;
}
object {
width:760px;
height:600px;
}
js
$('#button1').click(function(){
$('#Ahover').toggle()
});
Any help, what I'm I doing wrong? And is this even possible.
Thanks, got it working in the end by moving the script into tag.
Upvotes: 0
Views: 1106
Reputation: 559
Check out the working demo here - http://jsfiddle.net/x2qjdfwk/ The only change is to remove the show() function from the button as you are already applying the jQuery click event to it.
<p>Press the button</p><button id="button1">Show / Hide</button>
And make sure you include the jQuery library.
Upvotes: 0
Reputation: 315
html:
<p>Press the button</p><button id="button1" >Show / Hide</button>
<div id="Ahover"></div>
js:
$('#button1').click(function(){
$('#Ahover').toggle();
$("#Ahover").html('<object data="http://validator.w3.org/" />');
});
css:
div {
height: 100%;
}
object {
width: 100%;
min-height: 100%;
}
js fiddle: http://jsfiddle.net/SsJsL/
Upvotes: 0
Reputation: 240
Try This code:
HTML:
<p>Press the button</p><button id="button1">Show / Hide</button>
<div id="Ahover">
<object type="text/html" data="http://validator.w3.org/" >
</object></div>
CSS:
#Ahover {
display:none;
overflow: hidden;
border:1px ridge blue;
}
object {
width:760px;
height:600px;
display:inline-block
}
JS:
$('#button1').on('click',function(e){
$('#Ahover').toggle();
});
Demo is here:
Upvotes: 2