Switch to reveal a div that holds a different HTML page

I've been struggling to create a button that opens a div containing another HTML page. Initially, the button was working but the main page was opening with the div already visible, when I needed it hidden. Now, after making some changes, the button is not functioning at all.

Here's my code:

<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;
}

JavaScript:

$('#button1').click(function(){
   $('#Ahover').toggle() 
});

Link to Fiddle

I could use some help figuring out what I'm doing wrong. Is this even possible to accomplish?

Update: Managed to get it working in the end by moving the script into the <head> tag.

Answer №1

Give this code a try:

HTML:

<p>Click 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();
});

Check out the demo here:

https://jsfiddle.net/Dee0565/aaqfykz3/2/

Answer №2

Here is the HTML code:

<p>Press the button</p><button id="button1" >Show / Hide</button>
<div id="Ahover"></div>

This is the JavaScript code:

$('#button1').click(function(){
$('#Ahover').toggle();
 $("#Ahover").html('<object data="http://validator.w3.org/" />');
});

Here are the CSS styles:

div {
    height: 100%;
}

object {
    width: 100%;
    min-height: 100%;
} 

You can view this on JS Fiddle by clicking here.

Answer №3

Take a look at the demonstration in action by visiting this link - http://jsfiddle.net/a1b2c3d4/ The only adjustment needed is to eliminate the show() function from the button since you have already applied the jQuery click event to it.

<p>Click on the button</p><button id="button1">Display / Conceal</button>

Don't forget to include the jQuery library as well.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Loading Webfonts Asynchronously in NextJS Using Webfontloader

I am currently working on a NextJS app where I am using webfontloader to load fonts dynamically. function load() { const WebFont = require("webfontloader"); WebFont.load({ google: { families: fonts } }); } However, I ha ...

Creating an adaptable CSS triangle for an image

Is there a way to create a responsive triangle on an image that resizes properly and stays aligned? I'm currently having issues with it becoming misaligned. How can this be resolved? .image { width: 100%; } .image ...

A comprehensive guide on transferring user input onto a php text file

I am trying to implement a feature in my PHP code where the contents entered in a text box are uploaded to a text file. However, I only want them to be written if the string contains a specific pattern. Here is the modified PHP code: <?php $data = $_ ...

the object '[object Object]' of a distinct supporting nature

I encountered an error stating "ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays." This is my TypeScript file: this.list = data.json(); ...

Looking to verify an "else" condition within an alert in ReactJS?

In my code below, there is a text field and a button. If the text field is not filled and the button is submitted, an alert message should appear asking to fill in the input text. Currently, when I submit the button without filling the input text, the ale ...

What is causing the resistance in changing the color of my current navigation items?

I've encountered a small challenge with my header section. Despite multiple attempts, I'm struggling to change the color of the 'current' menu item. It seems that overriding Bootstrap's default color is proving to be more difficult ...

What is the best way to convert and update document fields in MongoDB to GeoJSON format using Java?

I have a collection in mongodb that stores information about airports and I need to perform some Geospatial Queries. One example document from this collection looks like this: { "_id" : ObjectId("528e8134556062edda12ffe6"), " ...

Tips for changing a fullscreen HTML5 video appearance

I discovered a way to change the appearance of a regular video element using this CSS code: transform: rotate(9deg) !important; But, when I try to make the video fullscreen, the user-agent CSS rules seem to automatically take control: https://i.sstatic. ...

Function for when Tic Tac Toe results in a tie

I have developed a tic tac toe game using Javascript and now I have two questions. 1. How can I add a "start" button so that the game can only be seen or played after clicking on the button? And now for the challenging part: In case of a draw, I want t ...

Display the most recent information from a MySQL table instantly using jQuery after the data has been updated

I have a table called user. The data is shown below: +----------+----------+ | ID | money | +----------+----------+ | 1 | 100 | | 2 | 200 | +---------------------+ The code in my file t.php looks like this: / ...

0 situation where using an empty value with PHP SESSION

Good Morning! I'm encountering an issue with a variable named "var" which can be 0. I'm trying to check if the variable is null, and if it's not, I save it in a PHP session and call another page. When I check the session on the new page, it ...

Is it possible to use Javascript to query the neo4j database?

After creating a geohash neo4j database for NYC Taxi data, the next step is to visualize it on a map. I decided to use Leaflet as a JavaScript library. Using static data, I was able to plot geohash data in Leaflet: https://i.sstatic.net/AtQKZ.jpg Now, my ...

Enhancing the Efficiency of Android Programming

For my application, I am currently displaying 12 markers on a map, each of which triggers a dialog box showing the location's address when tapped. However, I believe there is a more efficient way to handle this. I have been experimenting with creating ...

Aligning the navigation links vertically

I am working on aligning my navigation bar vertically, even when I scroll the page. I found a method in another thread which suggests using the following CSS code for vertical alignment: #container { position: absolute; top: 50%; height: 400p ...

Difficulty arising from the final column of average sums - Information extracted from JSON using Angular JS

I am facing a problem with calculating the average total. I need to determine the average sum using a specific formula, but the code provided does not calculate the last column of Average. I am looking for a desired result and would appreciate any assistan ...

Why isn't this code from CodePen functioning on my local server?

I am experiencing an issue with a pen from CodePen that is not working on localhost, while everything else seems to be functioning correctly. I am puzzled as to why it is not working and how I can resolve this. CodePen Link After compiling SCSS to CSS and ...

Errors during the compilation of Webgl shaders in the Google Chrome browser

Currently, I am in the process of learning three.js by following this tutorial: . Despite the tutorial working well, I have encountered errors in my own code which seem like this: ERROR: 0:26: 'nuniform' : syntax error Three.js:325 precision hi ...

Unusual express middleware usage in NodeJS

app.use(function(req,res,next){ console.log('middleware executed'); next(); }); app.get('/1',function(req,res){ console.log('/1'); res.end(); }); app.get('/2',function(req,res){ console.log('/2'); res.end() ...

Split the input string into individual characters for each entry

As a beginner in Angular, I am currently exploring ways to split a single input field into separate inputs for each word. I attempted to achieve this using jQuery but struggled and also learned that mixing jQuery with Angular is discouraged. Here's th ...

How can the client obtain the JWT from the server after it has been retrieved from the API?

I am currently working on implementing authentication in my Next.js and Strapi project. The process involves the client sending a post request with credentials to the Next.js server, which then sends a post request to the Strapi API to log the user in and ...