How can two unique links toggle the visibility of divs with two specific IDs?

I am developing an interactive questionnaire that functions like a 'create your own adventure' story. The questions are shown or hidden depending on the user's responses. Below is the HTML code:

<!-- TIER 3
================================================== -->
<!--From Steak/Fries-->
<div id="SteakFries" class="hide">
    <p>I'd rather...</p>
    <span class="responseRead"><img class="prompt" src="http://fakeimg.pl/50" data-respnseto="Read">Read a Best-Seller on the Beach</span>
    <span class="responseExplore"><img class="prompt" src="http://fakeimg.pl/50" data-respnseto="Explore">Explore Ancient Ruins &amp; Natural Wonders</span>
</div>

<!--From Chamagne/Caviar
To travel style-->

<!--From Gastro-->
<div id="GastroPubs" class="hide">
    <p>I'd rather...</p>
    <span class="responseExplore"><img class="prompt" src="http://fakeimg.pl/50" data-respnseto="Explore">Explore Ancient Ruins &amp; Natural Wonders</span>
    <span class="responseVisitCity"><img class="prompt" src="http://fakeimg.pl/50" data-respnseto="VisitCity">Visit City Landmarks &amp; Theatres</span>
</div>

<!--From Wine/Cheese-->
<div id="GastroPubs" class="hide">
    <p>I'd rather...</p>
    <span class="responseVisitCity"><img class="prompt" src="http://fakeimg.pl/50" data-respnseto="VisitCity">Visit City Landmarks &amp; Theatres</span>
    <span class="responseRelaxParadise"><img class="prompt" src="http://fakeimg.pl/50" data-respnseto="RelaxParadise">Relax in an Over-Water Bungalo in Paradise</span>
</div>

<!--opens these divs-->
<!-- TIER 4 (Styles Discover)
================================================== -->
<!--From VisitCity-->
<div id="VisitCity" class="culturalChameleon hide">
    Cultural Chameleon
</div>

<!--From Champagne/VisitCity-->
<div id="RelaxParadise" class="fiveStar hide">
    Five-Star Fanatic
</div>

<!--From Explore-->
<div id="Explore" class="activeAdventurer hide">
    Active Adventurer
</div>

<!--From Read/VisitCity-->
<div id="Read VisitCity" class="sunSeeker hide">
    Sun Seeker
</div>
<!--================================================== -->
</div>

Based on the link clicked in Tier 3, the corresponding div in Tier 4 is displayed. This functionality is achieved with the following jQuery code:

var data = "";
$('.prompt').click(function(){
    data = $(this).attr('data-respnseto');
    console.log(data);
    $('.hide').hide();

    $('#' + data).fadeIn(600);
});

However, there is an issue with displaying the last item in Tier 4 when clicking either of the links in Tier 3 that have the attributes:

data-respnseto="Read"
data-respnseto="VisitCity"

Currently, the code only looks for one ID to display in Tier 4. Any suggestions on how to display item 4 in Tier 4 when the user clicks either of the links in Tier 3? Your help would be greatly appreciated.

Answer №1

Give this a shot:

let info = "";
$('.trigger').click(function(){
    info = $(this).data('details');
    console.log(info);
    $('.hide').hide();

    $("div[id*='"+ info + "']").fadeIn(600);
});

View JSFiddle Demo

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

Guide to modifying Button on fetch response in React Native

After receiving a response from the server, I need to adjust the button based on the friends_status field in the following response: { "responseHeader": { "type": "314", "status": "200", "message": "Successfully found the profile" }, "ne ...

AngularJS: Issue with Variable Value Rendering

I recently started working with Angular. In my JavaScript file, I have the following code: App.controller('ProductController', ['$scope', 'ProductService', function ($scope, ProductService) { console.clear(); console. ...

Error: The Stripe webhook payload must be submitted as either a string or a Buffer

I'm currently working on setting up a subscription system using Stripe. I have mostly followed the code from their documentation, but I keep encountering the following error: Webhook signature verification failed. Webhook payload must be provided as a ...

leveraging angular service with ionic framework

(function () { 'use strict'; angular .module('app') .factory('UserService', UserService); UserService.$inject = ['$http']; function UserService($http) { var service = {}; ...

Handling Asynchronous API Requests with AngularJS

I am facing an issue with displaying data from API in my files foo.js and foo.html. While fetching information asynchronously in foo.js, I store it in an object that should be accessible in foo.html. However, despite receiving the data correctly, I am una ...

When scrubbing through videos, Chrome consistently throws a MEDIA_ERR_DECODE error

Encountering a MEDIA_ERR_DECODE error while scrubbing in Chrome on two different PCs. One PC runs Windows 7 with Chrome version 26, and the other runs Windows 8 with Chrome version 27. This issue occurs across all videos. When attempting to scrub on the v ...

Update the radio button to display the value entered in the text input field

I'm trying to implement a feature where the value of a text box can be set as the value of the selected radio button. Below is the code I have: HTML <form action="add.php" id="registration" method="post" name='registration' onsubmit="re ...

Storing text containing < and > symbols in a PHP Database

I am facing an issue trying to save a string from my web application into the database I'm connected to. The JavaScript successfully passes the string to PHP using AJAX, but when the insertion is performed, everything after the "<" or ">" symbo ...

What is the best way to delete an item from a React array state?

In my Firebase database, I have an array stored under the root branch called Rooms. Within the app, there is a state named rooms which is also an array. I successfully set it up so that when a user enters a new room name and submits it, it gets added to th ...

Identifying when floats exceed their limits

Is there a way to identify overflow on floating elements? It's important to note the difference between setting overflow to visible or hidden. overflow: visible; overflow: hidden; Do all floated elements inherently contain overflow? Why is it chal ...

"Enhance your web development with Vue.js and Vue-chart.js for beautiful linear

I'm currently struggling to implement a linear gradient background on my Vue-chart.js line chart. Despite searching high and low, the documentation and examples available are not proving to be helpful. After importing the Line component from vue-char ...

The post data is being altered by jQuery AJAX when posting

When I'm utilizing jQuery post to send checkbox values to another file, the page works fine without any issues. However, when using jQuery post, it seems to interfere with the array and causes it to malfunction. The form fields for my radio field are ...

Leverage the power of jQuery and checkboxes to sort through posts

I have integrated the quicksand plugin into my WordPress theme to load posts from a selected category. Recently, I added custom taxonomies and field values to each post, and now I want to arrange my posts based on these criteria. As someone who is new to ...

Ways to minimize an array of objects by shared key values?

Suppose I have an array of objects structured like this: var jsonData = [ {"DS01":123,"DS02":88888,"DS03":1,"DS04":2,"DS05":3,"DS06":666}, {"DS01":123,"DS02":88888,"DS03":2,"DS04":3,"DS05":4,"DS06":666}, {"DS01":124,"DS02":99999,"DS03":3,"DS04" ...

Ways to eliminate the final empty space in a grid

Looking to create a layout with 5 boxes? Currently, I have managed to set up the grid structure, but the issue is that there is still some space below the last item in the grid. Below is the styled component for Container: const Container = styled('di ...

Disabling the background shadow effect in Angular Material's Accordion

I successfully disabled the background shadow on the Angular Material Accordion in this demonstration by incorporating the following CSS rule: .mat-expansion-panel:not([class*='mat-elevation-z']) { box-shadow: none !important; /* box-shadow: ...

When collapsing an accordion, Bootstrap radio buttons fail to properly select

I have attempted various methods to achieve the desired functionality of having the accordion content close and open accordingly when checking a radio button, while also having the button visually appear as 'checked'. For a more in-depth example, ...

No content in a DIV element causing unusual height in IE7

UPDATE 1: After some experimenting, I discovered that by removing the width:100% property from the div, I am able to achieve the desired outcome of having a height of 0 when the div is empty. However, I still require the div to have a width of 100%, which ...

JavaScript Datepicker Formatting

I need to modify the date format of a datepicker. Currently, it displays dates in MM/DD/YYYY format but I want them to be in DD-MM-YYYY format. <input id="single-date-picker" type="text" class="form-control"> Here's the JavaScript code: $("# ...

Developing a pop-up feature that triggers upon clicking for a miniature rich text editing

Looking to integrate the Tiny rich text editor into my code. Check out the TextEditor.js component below: import React from 'react'; import { Editor } from '@tinymce/tinymce-react'; class App extends React.Component { handleEditorCha ...