When the button is clicked in Jquery, the HTML is loaded into one div while simultaneously hiding the other div

Looking for some assistance with JQuery, as I am relatively new to it. In my project, I have three divs set up - the first serving as the header, the second containing a slideshow of images along with buttons, and the third that should be displayed upon button click. However, once the third div is loaded with an external HTML file after clicking the button, the second div disappears. I've included screenshots below showcasing the issue: output screenshot view screenshots

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="MainScreen.css">
<script type="text/javascript"></script>
<script src="MainScreenJavaScript.js"></script>
<script 
   src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<style>
     body{
        font-family: "Times New Roman", Georgia, Serif;
         }
</style>


</head>
<body>

<!-- Navbar top -->
<div class="topnav" id="myTopnav">
<a href="#home" class="colors" >HOME</a>
<a href="Resume.html"  class="colors" >ABOUT</a>
<a href="contact.html" class="colors" >CONTACT</a>
<a href="#icon" class="icon" onclick="myFunction()">&#9776;</a>
</div>

<!--Slide show -->
<div class="slideshow-container ">
   <div class="mySlides fade">
   <img src="laptop.jpg" class="image">
   <div class="text">Keen to learn many things</div>
 </div>

 <div class="mySlides fade">
  <img src="travel2.jpg" class="image">
   <div class="text">Like to travel</div>
 </div>

 <div class="mySlides fade">
  <img src="education.jpg" class="image">
  <div class="text">Education and Background</div>
 </div>

 <div class="mySlides fade">
  <img src="cook1.jpg" class="image">
  <div class="text" >
    <button id="cookButton" onclick="loadExternalHtml()">Love for 
        Cooking</button>
  </div>
  </div>

  <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
  <a class="next" onclick="plusSlides(1)">&#10095;</a>
  </div>
  <!-- dots-->
  <div style="text-align:center">
      <span class="dot" onclick="currentSlide(1)"></span>
      <span class="dot" onclick="currentSlide(2)"></span>
      <span class="dot" onclick="currentSlide(3)"></span>
      <span class="dot" onclick="currentSlide(4)"></span>
   </div>

   <div id="content"></div>

   <script type="text/javascript">
     var slideIndex =1;
      showSlides(slideIndex);

      function loadExternalHtml(){
          $(document).ready(function(){
           $("#cookButton").click(function(){
             $("#content").load("foodBlog.html"); //load html page onclicking the button

      });

    });
   }


  </script>

   </body>
 </html>

Here is my foodBlog.html

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="stylesheet" 
      href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/
    bootstrap.min.css">
<script 
  src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
 </script>
   </head>

   <body>

  <div class="container" >
       <div class="row">
     <div class="col-md-4">
    <div class="thumbnail">
    <img src="text.jpg" class="img-rounded"  alt="text" 
   style="width:100%;height:250px">
   <h3>text</h3>
   <p>It is a street food</p>
  </div>
 </div>
  <div class="col-md-4 ">
   <div class="thumbnail">
    <img src="text1.jpg" class="img-rounded"  alt="text1" 
    style="width:100%;height:250px;">
  <h3>text1</h3>
   <p>text1</p>
 </div>
 </div>

 <div class="col-md-4">
   <div class="thumbnail">
    <img src="text2.jpg" class="img-rounded"  alt="text1" 
     style="width:100%;height:250px;">
    <h3>text2</h3>
     <p>text2</p>
    </div>
   </div>

  </div>
  </div>

 </body>
</html>

Answer №1

<section id="info"></section>

Within the realm of presentation-area, the element's behavior is dictated by the CSS properties assigned to both info and presentation-area. What changes will occur if you relocate info outside of presentation-area?

Experiment with: float:left; or overflow:hidden; for content

The crucial aspect here lies not in the HTML or jQuery code, but rather in the specific CSS styles applied to these IDs and classes.

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

Align two DIVs in the correct layout: One as a sidebar that remains fixed, and the other as an expanding element

I am currently working on a code snippet to build a basic website featuring two main sections: a sidebar and the main content: html, body { height: 100%; margin: 0; } .container { display: flex; flex-direction: row; height: 100%; } .sidebar { ...

Using Laravel, I have managed to pass the start and end price range through an ajax get request, but I am facing difficulties in returning it correctly

Array Result after selecting price rangeWhen attempting to retrieve products based on the specified price range, I call the controller function with the input values: <script> function send(){ var start = $('#amount_start').val(); var ...

Why is Chrome ignoring the flexbox CSS in the footer section of my website?

My footer flexbox CSS is working on various browsers and devices, but for some reason, Chrome on my iMac is not responding correctly. The website is www.batistaelectric.com. It works on my iPhone Chrome browser, Safari iPhone browser, iMac Safari browser, ...

Locate and dismiss a toast message (Toastr)

I have a webpage where I can add multiple popup notifications called toasts dynamically using the toastr plugin found at https://github.com/CodeSeven/toastr. Each toast has an Ok link that, when clicked, should only close that specific toast and not all v ...

Guide on retrieving the initial value from HTML and passing it to the controller in AngularJS during page load

<ul> <li ng-init="formData.mdpSunday='5'"> <input ng-model="formData.mdpSunday" name="mdpSunday" type="radio" value="5"> </li> </ul> app.controller(&a ...

Disabling user interface during a partial page load using JavaScript

On my ASP.NET page (WebForm1), I use a modal dialog WebForm2 (via the OpenForm2() JavaScript function) for additional processing. After closing the dialog, I update the UpdatePanel using JavaScript. However, I encounter an issue where the UI is not blocked ...

Show the updated count retrieved from a specific record in a database table using Ajax technology

I am looking to retrieve the latest ID from a database table and then increase it by 1. I want to display this incremented value in either an Input or Label element of HTML, instead of using tables as most tutorials do. Below is a snippet of my code: inde ...

Retrieving all selected values from a dropdown list using Jquery Chosen upon form submission

I am currently utilizing the Jquery Chosen Plugin to enhance my website. One of the features I have implemented is a MultiSelect List on my Page. <select name="articles_on_this_menu" multiple="multiple" data-placeholder="Choose Articles" id="articles_ ...

Design a modern slider with a button that triggers a pop-up modal window

Recently Updated I am working on a testimonial slider using slick slider, and I want to incorporate a modal within each slide. In my custom post type 'Testimonials' (also known as 'getuigenissen' in English), I have various Advanced C ...

Having trouble with JQuery on your Joomla 2.5 site?

Seeking assistance with implementing jQuery in my Joomla 2.5 website to switch between two images. While I have successfully achieved this on a static HTML page, I'm facing difficulties in Joomla. Here is the code snippet I am attempting to use within ...

Analyze two sets of JSON data and compile a new JSON containing only the shared values

I am trying to generate two JSON arrays based on a shared property value from comparing two sets of JSON data. this.linkedParticipants =[ { "id": 3, "name": "Participant 2", "email": "<a href="/ ...

AngularJS inputs using ng-model should be blank when in the pristine state

Check out this input element within an HTML form: <input ng-model="amount" /> Currently, the input displays as $scope.amount = 0 in the controller. I want to start with a blank input field instead. This way, users can easily input data without havi ...

Using HTML5 to create an event handler for a click event

I am currently tackling a test paper for the Microsoft Certification in Programming in HTML5 with JavaScript and CSS3. I have encountered a question for which I cannot find the answer: The Question: You have been tasked with creating a JavaScript functio ...

Adjust the stroke and fill color of an SVG upon hovering over it

I have a unique SVG image with an intricate stroke around it that matches the color of a filled icon. Positioned on a black background within the image, you can view my example here: https://jsfiddle.net/o48629qs/ The challenge I am facing involves changi ...

Can I obtain page redirect data using Ajax?

Is there a way to detect URL redirects when making jQuery Ajax requests? For instance, if a request to http://api.example.com is redirected to http://api2.example.com in PHP, can this redirection be captured? Scenario: I am using AJAX to load pages into a ...

The curious behavior of $viewContentLoaded in Angular

For my jQuery code, I wanted it to run immediately after the template view was loaded and the DOM was modified. To achieve this, I initially used the $viewContentLoaded event in my controller. $scope.$on('$viewContentLoaded', function(){ // ...

"Render Failure" JavaScript and CSS files

I'm encountering a peculiar issue while attempting to load certain JS and CSS files. Within my ASP.NET MVC Web Project, I have an Index.html file where I've specified the loading of script files. It's worth noting that I have modified the U ...

Bespoke Video Player using HTML5 with "Nerdy Stats" Feature

I have been given the task of creating a streaming video testing framework for internal metrics and measurement purposes. Essentially, I am looking to develop an HTML5 player that can handle streams and provide performance data related to: - Average Bitr ...

Uploading images seamlessly through ajax

Despite the abundance of tutorials, I am struggling to make them work. In my input form for file upload, I have: <input onChange="userPreviewImage(this)" type="file" accept="image/*" style="display:none"/> Here is my Javascript code: function use ...

Dialog loading is only possible to occur once, but there are specific conditions that must be

My HTML file contains a button that triggers the loading of a modal dialog to search for information and return the results to the form. The button and search function work correctly, but after returning data to the form and closing the dialog, the button ...