Switch up the displayed text according to the user's clicks

After extensive research on the topic, I have come across numerous methods but none that fully meet my requirements.

In Typo3, I am attempting to create multiple links that, when clicked, will change the text displayed in a designated area below the links. Whenever a new link is clicked, I want the previous text to be replaced with the information from the newly selected link.

To simplify, think of it as a picture gallery where instead of images, the text changes. Please let me know if further clarification is needed. Any assistance would be greatly appreciated.

UPDATE: I am aiming for a similar functionality to what can be seen on this page. However, instead of the div becoming visible on hover, I need the text to display and remain OnClick until the next selection is made.

While currently using code for hover effects, I require it to trigger on click for display purposes.

<script language="Javascript">
<!--
function ShowPicture(id,Source) {
if (Source=="1"){
if (document.layers) document.layers[''+id+''].visibility = "show"
else if (document.all) document.all[''+id+''].style.visibility = "visible"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
}
else
if (Source=="0"){
if (document.layers) document.layers[''+id+''].visibility = "hide"
else if (document.all) document.all[''+id+''].style.visibility = "hidden"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
}
}
//-->
</script>
<style type="text/css">
#Style {
position:absolute;
left:218px;
top:300px;
visibility:hidden;
border:none 1px #CCC;
padding:5px;

}
</style>

<div id="CC1" style="position:absolute; left:30px; top:472px;"><a href="#" STYLE="TEXT-DECORATION: NONE" onMouseOver="ShowPicture('Style',1)" onMouseOut="ShowPicture('Style',0)"><center><h1 style="color:white; font-size:125%;">Lorum Ipsum<center></a></div>
<div id="Style"><img src="http://www.example.org/fileadmin/template/images/CCSS/TextBox.png"><div style="position: relative;top:-285px;font:12pt;font-weight:bold;color: #0067b2;margin-left: 15px;width:280px">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div></div>

I have successfully implemented the desired effect using the provided code. My only challenge now is that all divs are initially displayed when the page loads, and one must be clicked to hide the others. Any suggestions on how to improve this behavior?

function showonlyone(thechosenone) {
 $('div[name|="newboxes"]').each(function(index) {
      if ($(this).attr("id") == thechosenone) {
           $(this).show(200);
      }
      else {
           $(this).hide(600);
      }
 });
}

Answer №1

Here is a simple illustration of how you can accomplish this task. Without specifying the source of the new text, I have utilized a data-* attribute for demonstration purposes. You have the flexibility to adjust this according to your requirements, whether it involves another element, an AJAX call, etc.

<p id="message"></p>    
<a href="#" data-text="Message #1" class="link">Show message #1</a><br>
<a href="#" data-text="Message #2" class="link">Show message #2</a><br>
<a href="#" data-text="Message #3" class="link">Show message #3</a><br>
<a href="#" data-text="Message #4" class="link">Show message #4</a><br>
<a href="#" data-text="Message #5" class="link">Show message #5</a><br>
$(".link").click(function() {
   $("#message").text($(this).data("text"));
});

Example fiddle

Answer №2

The issue has been resolved thanks to the utilization of the rgaccordion extension in this specific case.

For those utilizing TemplaVoila, it is possible to effortlessly generate an FCE that suits your markup needs

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

Troubleshooting: Inconsistencies with saving input values to a variable in jQuery

I am encountering an issue where I cannot save the input data in a variable. When I do, it saves as a blank space or as 0 if it's an integer. Below is my code snippet: function attachKeyupEventDescuento(inputElement, i) { var cantidad = $(&apos ...

The CSS background image in PNG format displays a white line at the beginning of the transparency

How can I remove the white border that appears on PNG images with transparency when used as a background with CSS on retina devices? .background { background: url('../image.png') no-repeat; } ...

extracting values from an HTML document to populate a Java email template

I'm currently working on a contact form that lets users input their information and sends an email to the specified email address. I've been struggling with extracting the parameters from the HTML file and linking them to the email components. Fo ...

Configuring the start_url and scope within the manifest.json file for a React Progressive Web App

Can you explain the distinction in manifest.json between using start_url as "." versus "./", and likewise, setting scope as "." versus "./"? I am currently migrating a React app behind a reverse proxy server accessed through https://www.example.com/scorer ...

The CSS submenu is appearing below the jQuery UI tabs

On my webpage, I have designed a vertical CSS menu for the left side with submenus, and on the right side, I added jQuery UI tabs (in asp.net). However, the issue is that my submenus are appearing behind the jQuery tabs, as illustrated in the image below: ...

Can you explain the significance of the 9 in this width attribute declaration?

Can someone explain the purpose of this code snippet? My assumption is that it could be a browser hack, but I haven't been able to decipher its exact function. width: 500px\9; Is there any specific reason for using \9 in this context? ...

Tips for accessing and modifying parent state resolve data within the onEnter function of a child state in a UI router

Within my ui-router state configuration, I have the following setup: Parent state $stateProvider .state('profile',{ url: '/profile', views: { 'contentFullRow': { ...

Assign a unique CSS style to each Popper

I am currently working on a component that generates 6 unique experiences, each with its own popper. My goal is to customize the styles of each popper in terms of background and position, and ensure that all poppers display images of the same size. Despite ...

Using CSS to responsively align the logo in the header with the name positioned on both sides

I'm struggling to align my logo in the center of my header. I want it to appear like this when displayed correctly: "Name" Logo "Surname". The logo should be centered, with the "name" on its left and the "surname" on its right. (Please refer to the im ...

How to vertically center a form element in Bootstrap 4

As a newbie to using bootstrap 4 for the first time, I expected vertical alignment of elements to be easy, especially with flex being touted as the simplest way to achieve this. The issue: Struggling to vertically align my form element within my navigatio ...

Unable to get click function to work with multiple div elements

Using four div elements, I have implemented a feature where clicking on the first div causes all other div elements to change opacity. This is working correctly. However, I would like the opacity of the first div to remain unchanged when moving to another ...

Replace the facebook plugin using JQuery libraries

Does anyone know how to remove the like button on top of the 'Like box' Facebook plugin using JQuery? I have imported the like box from Facebook and I want to eliminate this like button, but Facebook does not allow me to do so. Therefore, I am t ...

What are the differences between a Chrome app and extension? Is there any other way to access the tabs currently open in your

I need to develop an app that can access the tabs a user has open, but I'm struggling to find a way to do so without having my app run in Chrome itself. Creating an extension restricts the UI significantly, which is problematic since my app requires a ...

Automatic Slideshow

I am trying to implement autoplay in my slider, but I am having trouble figuring out how to do it. The slider itself is working fine, but I know that I need to use an interval for the autoplay feature. If anyone could provide some assistance on how to ac ...

What is the process for defining a date range in HTML5?

I am currently working on a wedding website and I am trying to set up a countdown for the wedding date. However, I am having trouble figuring out how to correctly display the countdown. https://i.sstatic.net/iGikh.png Here is the code snippet that I am u ...

Posting a form in ASP.net software by utilizing an element prefix of "ct100$"

I'm currently in the process of creating a website master page that includes a form for member login. Below is the markup from the master page: <form id="loginForm" action="account.aspx" method="POST"> <div class="div-topHead"> <input ...

Can you explain the meaning of `suppressed_by_user` in Google One Tap?

When the user clicks sign in, I want the one tap to appear. The code below works fine when it runs as soon as the page loads. However, if I try to run it on click, I get the error suppressed_by_user. I do not have an ad blocking plugin enabled and I am uns ...

Optimal Strategies for Mapping Out Your Travel Plan

I've been working on setting up routes for my backend and I've encountered two different approaches. I'm curious to know which one aligns better with best practices, or if neither is ideal. Despite the minor differences between them, I am ea ...

What is the best way to merge several CSS class selectors into a single one?

I am facing an issue with using multiple selector classes in my HTML elements. For example: .rt-grid-6 { ... } .largemargintop { ... } .rt-left { ... } Currently, I have to use these classes repetitively in my HTML like this: <div class="rt-grid-6 l ...

Can JavaScript be used to navigate to a specific tab on a webpage?

Are there any scripts available to navigate to the next or previous tab in a browser? Specifically, if I am using Google Chrome, can I use JavaScript to move to the tab on the right? ...