Concealing the identification of a different page upon clicking the "read more" button

I have created a page containing descriptions and "read more" buttons for each section (4 identical divs). When the "read more" button is clicked, it should redirect to another page displaying the full description of all 4 sections. However, when the "read more" button of a specific section is clicked, I want it to direct to the full description of only that section while hiding the descriptions of the other sections.

HTML CODE

one.html

<html>
<head>
<script type="text/javascript">
$(document).ready(function() {
    $(".a1 a").click(function() {
        $("#a2_bio").hide();
        $("#a3_bio").hide();
        $("#a4_bio").hide();
    });
});
</script>
</head>

<body>
<style type="text/css">
p {
    font-size:12px;
    font-family:"Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
    text-align:center;
}
.a1, .a2, .a3, .a4 {
    width:300px;
    height:200px;
    float:left;
    margin-left:30px;
    border:1px dotted #CCCCCC;
    padding:1px;
    background:#CCC;
}
.images {
    width:100px;
    height:75px;
    margin:0 auto;
    border:1px solid #666;
    margin-top:30px;
    background:#C36;    
}

.a1 a, .a2 a, .a3 a, .a4 a {
    float:right;
    margin-right:10px;
    width:75px;
    height:20px;
    font-size:11px;
    color:#060;
}
</style>

<div class="a1">
    <div class="images"></div>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
    <a href="two.html#a1_bio"> Read more </a>
</div>

<div class="a2">
    <div class="images"></div>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
    <a href="two.html#a2_bio"> Read more </a>
</div>

<div class="a3">
    <div class="images"></div>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
    <a href="two.html#a3_bio"> Read more </a>
</div>

<div class="a4">
    <div class="images"></div>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
    <a href="two.html#a4_bio"> Read more </a>
</div>

</body>
</html>

two.html

<html>
<body>
<style type="text/css">
#a1_bio, #a2_bio, #a3_bio, #a4_bio {
    width:800px;
    height:200px;
    background:#CCC; 
    border:1px solid #666;
    margin-bottom:20px !important;
    float:none;
    margin:0 auto;
}

#a1_bio p, #a2_bio p, #a3_bio p, #a4_bio p {
    font-size:12px;
    font-family:"Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;   
}
</style>

<div id="a1_bio">
    <p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>

<div id="a2_bio">
    <p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>

<div id="a3_bio">
     <p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>

<div id="a4_bio">
    <p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>

</body>
</html>

Answer №1

To achieve this functionality, you can implement the following JavaScript code: In the provided two.html file, ensure that all div elements are hidden by default. Then, in one.html, include a URL parameter like this: two.html?url=a2_bio

function extractUrlParams() {
    var params = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(match, key, value) {
        params[key] = value;
    });
    return params;
}
var targetDivId = extractUrlParams()["url"];
$('#'+targetDivId).show();

Answer №2

Give this code a try:

DEMO

JavaScript:

 var paths = window.location.pathname;
 $(paths).show();

CSS:

 #section1, #section2, #section3, #section4
    {
    width:600px;
    height:150px;
    background:#F0F0F0; 
    border:#333 1px solid;
    margin-top:10px !important;
    float:left;
    margin:0 auto;
    display:none;
    }

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

What is the best way to ensure proper spacing between menu options on a navigation bar?

Here is a snippet from the style.css that will provide some context. .padding-fix { padding: 0; } div.navigation { float: right; } .navigation ul { list-style: outside none none; margin: 0; padding: 0; position: relative; } .navigation ul#n ...

Exploring the world of Bootstrap Twitter 3.0 alongside the wonders of Knockout

When utilizing Twitter Bootstrap, the validation classes like has-error or has-warning must be added to the wrapping form-group element to style both the input and its label. However, Knockout-Validation directly adds the class to the input element itself. ...

Using the map function with an array of objects: A guide

Utilizing the following dataset to populate the listData state in React: [ { "Key": "Anchorage TAC 82.tif", "LastModified": "2019-04-07T03:25:51.000Z", "ETag": "\"9f904f2219d1edf3fa39b171c98de924-6\"", "Size": 28135199, ...

A Guide to Organizing Vue Js: Dividing 'methods', 'data', 'computed', and More into Separate JavaScript Files

Is it feasible to separate methods, data, computed properties, etc. into individual .js files and then import them into a component.vue file? I prefer not to include all JavaScript logic in a single .vue component. My ideal code organization for each com ...

The issue of jumpy CSS background on full screen mode for mobile devices is causing

While developing a web app, I encountered an issue with the responsive (parallax) full screen background. On mobile devices, the background does not extend below the toolbar, causing a jumpy effect when scrolling up and down in Firefox. I have tried differ ...

What is the functionality of the disabled attribute on an option tag within a dropdown select menu?

I am working with a code snippet that involves understanding how the attribute:disabled functions on an <option> within a <select> element! Let's say I have a dropdown for ratings and I select the 5-star option (★★★★★). Upon sel ...

The synergy between HTML forms and Javascript

Is there a way to input a URL in a form and have it redirect to a different URL while keeping the original parameters? For example, if I enter , can it redirect to https://www.google.com/search?q=somequery? I believe this functionality can be achieved usi ...

Excessive greed in 2 column layout is causing left alignment issues

Check out the sample code here: http://jsfiddle.net/YUhgb/ HTML Markup <html> <body> <div class="left"></div> <div class="right"> <div class="container"> <div class="i ...

Adonis 5 and Vue encountering the error message 'E_ROUTE_NOT_FOUND'

I am currently working on a project using Adonis v5 as the backend and Vue 2 as the frontend. I have encountered an issue where, after building the Vue frontend into the public Adonis folder, accessing a specific route directly in the browser results in an ...

The dropdown menu vanishes from sight as soon as the cursor moves away from a link

Recently, I encountered an issue while trying to create a dropdown menu using Jquery. The problem arose when attempting to select the second link, as the entire menu would disappear. Additionally, is there a way to ensure that only one dropdown menu is vis ...

What is the best way to replicate the shooting function found in the Space Invader game?

For a school assignment, I am looking to create a function that is similar to the shooting mechanism in the Space Invader game. The only issue is that I have not yet learned css or canvas. Although I have watched numerous tutorials using those technologies ...

html5 canvas not displaying images

When trying to load images, only a blank canvas appears instead of the intended graphics. <canvas width=800 height=500 id='egypt_id'></canvas> <script> //Initialize variables and image objects var canvas = document.getElement ...

Is it possible to use JavaScript to switch between HTML tags?

One of the things I love about using element.classList.toggle() is how easy it is to switch between classes without needing extra CSS, especially when working with Bootstrap 4. But now I'm curious: is there a similar method for toggling between diffe ...

Reading data from Firestore in Next.js

I came across a Next.js starter that retrieves data from Firestore v9, but it only displays the data after a click event. How can I modify this code in Next.js to automatically show the data without needing to click? import { db } from '@/lib/firebase ...

Exploring the Potential of Using ngIf-else Expressions in Angular 2

Here is a code snippet that I wrote: <tr *ngFor="let sample of data; let i = index" [attr.data-index]="i"> <ng-container *ngIf="sample.configuration_type == 1; then thenBlock; else elseBlock"></ng-container> <ng-template #t ...

"Troubleshooting the slow loading of PDF files when using React's render-pdf feature

After creating a table with the ability for each row to generate and download a PDF using render-pdf npm, I encountered an issue. When the user clicks the download button, the PDF preview opens on a new page. However, there are problems with rendering as a ...

Saving an HTML5 canvas image to an MSSQL varbinary(max) field: A step-by-step guide

SAVING CANVAS IMAGE AS BASE64 STRING TO HIDDEN FIELD This script binds the base64 string to a hidden field on click event. save.addEventListener('click', function (event) { var dataUrl = canvas.toDataURL(); $('txtbx').val(dataUrl) ...

Rendering Highcharts React Pie Chart Multiple Times

Here is the code snippet: import React, { useEffect, useRef, useState } from "react"; import * as Highcharts from "highcharts"; import HighchartsReact from "highcharts-react-official"; export const PieChart = (props: any) =&g ...

Tips for removing JavaScript functions that were initialized after an ajax request

In my setup, there are two main pages: Page A and Page B. Page A consists of the following components: HTML for Page A JavaScript for Page A JavaScript for Page B Subsequently, I utilize an ajax call to inject Page B's HTML into Page A and trigger ...

Traverse through deeply nested objects and combine into a single string using the Lodash library

Currently, I am utilizing Lodash to streamline object manipulation. Within my object, there are three nested objects that I would like to iterate through, combining all of their respective children in various combinations. The goal is to include only one i ...