Here's a step-by-step guide on how to use jQuery to open a new page with the same image displayed when clicked

Seeking guidance as a newcomer to javascript, I'm struggling to find the best way to explain this dilemma. Any advice or assistance would be greatly appreciated.

Here is the HTML code in question:

<div class="col-md-4">
        <a href="stuffedd.html"><img src=""></a>
        <a href="stuffedd.html"><img src=""></a>
        <a href="stuffedd.html"><img src=""></a>
</div>

Upon clicking the images, the page redirects to stuffedd.html. The layout consists of two columns for images - a vertical thumbnail column and a larger image column in the middle.

Here is the structure:

<div class="middle containerscroll">
    <img src="" id="Mdrie" class="img-responsive ">
    <img src="" id="Mvier" class="img-responsive ">
    <img src="" id="Mvijf" class="img-responsive ">
</div>
div class="col-md-9 hidden-xs hidden-sm">
    <img src="" id="drie" class="img-responsive single">
    <img src="" id="vier" class="img-responsive single">
    <img src="" id="vijf" class="img-responsive single">
</div>

I've made some progress with jQuery :

$(document).ready(function(){

"use strict";
$( ".single" ).hide();

$( "#Mdrie" ).on('click',function() {     
 $('#drie').toggle();
$(".single").not('#drie').hide();

});

How can I ensure that stuffedd.html opens with the image I clicked on in the second column (all images with class .single)? Do I need to declare a variable and fill it in like this:

$( "var" ).show();

The website in question is: www.damondebacker.com in case you need to refer to it.

Answer №1

To clarify the issue, it seems like the second page should have some knowledge of the user's actions on the previous page. One approach could be to include a specific identifier in the URL that corresponds to the image:

<a href="stuffedd.html#Mdrie"><img src=""></a>

This way, the second page can easily retrieve the information. Alternatively, if you prefer not to include it in the URL, you could consider using a cookie or the LocalStorage object.

Answer №2

If you want to link an image from the first page to your URL, make sure to transfer the ID of the picture. By clicking on the Image, the link should look something like /stuffed.html?id=drie. When you visit the stuffed site, retrieve the parameter using jquery and display the corresponding image. Check out this helpful tutorial on URL Parameters and jQuery

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

React: maintaining referential equality across renders by creating closures with useCallback

I want to make sure the event handling function I create in a custom hook in React remains referentially equal across renders. Is it possible to achieve this using useCallback without specifying any variables it closes over in the dependencies list? Will o ...

What is the best way to position a banner image behind the navigation bar on my website?

I'm struggling to position the banner image behind the navigation bar on my website. It keeps appearing below the navigation bar, but I want it to be positioned behind the navigation bar instead. Here is the code I'm using: * { margin: 0; ...

Is it possible to link click and onchange events?

My code includes a function that updates an empty array and displays content in two separate HTML elements each time a radio button is selected from a select list. The content is displayed in a div and a ul element. Additionally, I want to display more rad ...

Can the navigation bar be filled automatically with content that corresponds to the anchors found within the content?

Currently, I am utilizing a Bootstrap frontend for the project at hand. The task I am tackling involves a significant amount of automatically generated content and code, which greatly simplifies the work process. My goal is to explore the potential of cre ...

Show the ajax appended html only after reaching a specific threshold

I am currently utilizing AJAX to fetch additional results from my database. Below is the basic script I am using: $('#loadmorebuilds-div').click(function() { $.ajax({ url: 'includes/loadmorebuilds.php?type=' + type + &ap ...

Content does not become interactive upon the initial loading of the page

I've modified a W3 schools slideshow template to use text instead of dots, but I'm encountering two issues 1: The first image doesn't load when the page loads. Although using a class ID and setting it to active fixes this issue, it leads to ...

Tips for looping through a JSON object?

Similar Question: How to extract a specific value from a nested JSON data structure? I am looking to loop through a two-dimensional JSON object, whereas I already know how to do so for a one-dimensional JSON object. for (var key in data) { alert(data ...

Executing a Python script within an HTML page using Django and extracting a variable from an input form

I have created a sentiment analysis Python script, but now I want to integrate it with an HTML page. The goal is to take input from the HTML form, process it using the Python script, and then display the results back on the HTML page. Currently, I am usin ...

Select element redirection problem

I have implemented a system with dependency drop-downs. <html> <body> <select id="parent-cat" name="parent-cat" onchange="getChildrenList(this.value)"> <option value ="">- Please Select -</option> ...

Problem with applying ng-class directive in AngularJS

I am currently developing an application using AngularJs and Bootstrap. My goal is to display the title of a 'scenario' with different styling based on its status, along with a specific icon. Initially, I attempted the following approach: <s ...

The comparison between createElement() and AJAX response

Currently, my website has a login form that updates the page with user data through AJAX after successful login. To maintain semantic integrity, I use JavaScript to remove the login form from the page once the user is logged in. However, when the user lo ...

What is the reason behind the trigger event failing to invoke events that are specified with addEventListener?

I have created a sample scenario: http://jsfiddle.net/y42pu5b6/ $(function(){ function ping (){ alert( "function fired" ); console.log("fired"); } console.log($("input#one")[0]); $("input#one")[0].addEventListener("chan ...

The Parallax effect functions properly on web browsers, but fails to work on mobile devices

I recently incorporated a parallax effect into the image gallery section of my website. While everything seems to be functioning perfectly in standard desktop and responsive modes on various browsers, I have encountered an issue when attempting to view the ...

Issues with jQuery focus function in Internet Explorer 11

Is there a way to set the focus on an anchor tag using the URL? Anchor Tag: <a id='714895'>&nbsp;</a> URL: jQuery Code: try { if(document.URL.indexOf("?ShowAllComments=True#") >= 0){ var elementClicked = "#" +location.hre ...

Exploring the power of JQuery's asynchronous promises within a labyrinth of nested

As a newcomer to Node.js and promises (specifically using Q.js), I am attempting to create a web scraper for a site with the following structure: Main Page: contains a list of categories, each with a link leading to a page listing various stores. List of ...

Increase the size of the textarea when it is clicked on and revert back to its original size when it

My question revolves around a text area that I am trying to manipulate through jQuery. The desired functionality is to increase the height of the text area whenever someone clicks on it, and decrease the height when clicking anywhere else on the screen. & ...

What exactly does a 'hoisted manifest' mean when it comes to using Yarn?

Encountering an issue while attempting to install a package using yarn, I am receiving the error message: expected hoisted manifest for \"myPackage#@material-ui/core#react-dom\" However, the concept of a 'hoisted manifest' is not entir ...

Once the image has been observed, what steps can be taken to close it?

I wish to implement a functionality where clicking on the view button will enlarge the image, and another click on the page will return it to its original size. import * as React from 'react'; import Box from '@mui/material/Box'; imp ...

The REACT- Popover feature seems to be having trouble showing the data from my json file

Within the menu/ section, the names of my invited guests are not visible; only the InfoIcon is displayed in the cell. My goal is to implement a Popover feature that will show all the information about the invited guests (including their names and locations ...

What is the best way to convert a table into a data array using jQuery?

I need help with a form and table integration. <form id="form_step" action="form_stepb.php" method="post"> Within the table, there are various rows containing dropdowns and input fields: <table class="data_table ...