Looking to update div content with a click on a circular image?

Could you assist me in overcoming this hurdle?

I have a website located here and I am looking to change the red div when I click on a rounded image.

I simply copied the code from another one of my websites!

Below is the code snippet for that particular section:

<div class="clearfix colelem" id="pu79"><!-- group -->
 <div class="browser_width grpelem" id="u79"><!-- group -->
  <div class="clearfix" id="u79_align_to_page">
   <a class="anchor_item grpelem" id="band"></a>
   <div class="clearfix grpelem" id="u80-4"><!-- content -->

   </div>
  </div>
 </div>
 <div class="PamphletWidget clearfix grpelem" id="pamphletu323"><!-- none box -->
  ...
  ...
  (rest of the code omitted for brevity)
  ...
  ...
</div>

Answer №1

There are numerous ways to achieve this task. Many implementations can be found in different libraries, and even Bootstrap has incorporated this feature.

However, I have quickly put together a custom solution for you to explore and interact with. Check out the Fiddle example and click on the red circles to witness how they alter the content below.

HTML:

<ul class="circles">
  <li class="circle active" data-toggle="1"></li>
  <li class="circle" data-toggle="2"></li>
  <li class="circle" data-toggle="3"></li>
  <li class="circle" data-toggle="4"></li>
  <li class="circle" data-toggle="5"></li>
</ul>

<ul class="boxes">
  <li class="box active" data-toggled-by="1">
    <h1>Box 1</h1>
  </li>
  <li class="box" data-toggled-by="2">
    <h1>Box 2</h1>
  </li>
  <li class="box" data-toggled-by="3">
    <h1>Box 3</h1>
  </li>
  <li class="box" data-toggled-by="4">
    <h1>Box 4</h1>
  </li>
  <li class="box" data-toggled-by="5">
    <h1>Box 5</h1>
  </li>
</ul>

CSS:

ul {
  list-style-type: none;
}

li.circle {
  display: inline-block;
  border: 2px solid red;
  width: 50px;
  height: 50px;
  background: red;
  border-radius: 50px;
  margin-right: 25px;
  -webkit-transition: opacity .15s ease-in-out;
  -moz-transition: opacity .15s ease-in-out;
  transition: opacity .15s ease-in-out;
  cursor: pointer;
}

li.circle:hover {
  opacity: .5;
}

li.circle.active {
  border-color: black;
}

li.box {
  width: 90%;
  display: none;
  background: white;
  height: 300px;
  display: none;
}

li.box.active {
  display: block;
}

JavaScript (jQuery):

$('.circle').click(function() {
    // De-activate previously active circle
    $('.circle.active').removeClass('active');

    // Activate clicked circle
    $(this).addClass('active');

    // Get toggle ID of clicked circle
    var toggleId = $(this).data('toggle');

    // De-activate previously active box
    $('.box.active').removeClass('active');

    // Activate box with corresponding toggle ID
    $('.box[data-toggled-by="' + toggleId + '"]').addClass('active');
});

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

Is the div empty? Maybe jQuery knows the answer

I currently have a <div id="slideshow"> element on my website. This div is fully populated in the index.php file, but empty in all other pages (since it's a Joomla module). When the div is full, everything works fine. However, when it's emp ...

What is the best way to incorporate a year select feature in react-dates?

Swiping through months on react-dates until reaching the correct year can be frustrating. Would it be feasible to incorporate a selection option for both the year and month? ...

Broken responsive carousel using bootstrap

Looking for some help with a responsive bootstrap carousel issue. The carousel items adjust themselves below each other when the screen size is reduced. I want them to display as single items in the carousel. Here are the screenshots and the code. Please ...

Converting Hexadecimal Values to Base32-Encoding Using Javascript

I'm encountering a problem with converting a function from Ruby to Javascript (specifically node.js, but I prefer a solution that is compatible with browsers, if possible). Here is the hex-formatted sha256 digest: "0b08dfe80a49490ae0722b9306ff53c5ab ...

Spinning and disappearing gradually over a set period of time

Could someone please help me with creating an animation for one of my CSS DIVs? I want it to have an exit/entry effect with rotation/fadeout and then rotation/fadein, with a 10-minute delay between each iteration. I'm not sure if this can be achieved ...

Generating an html hyperlink for downloading and installing a provisioning profile

I have a download link for an app that is configured to only work on specific devices for testing purposes. The app downloads and installs without any issues, but it seems that the necessary certificate required to run the app is not being installed due to ...

The ng-style attribute failed to dynamically update

I have attempted to utilize ng-style in order to implement dynamic color changes specifically for IE11 compatibility. <tr ng-style="{'background-color':'{{section.Color}}'}"> Within my AngularJS module, I have a feature that al ...

The JQuery parseFloat() function seems to be consistently returning "NAN" whenever it is used with the .text property

I am currently encountering an issue with parsing the text property of an input element identified by the id currency-converter. My goal is to convert this text into a floating-point value so that I can proceed with applying mathematical operations to conv ...

ajaxStart event does not trigger when making an Ajax POST request

My ajaxStart event functions properly for ajax loads, but it does not work at all when I do a POST request. The following code is consistently rendered on all pages: $(document).ajaxComplete(function () { hideIcon(); if (stepState !== &a ...

The ng-model directive in drop-down selection elements

I have a series of questions along with their answers, and I want the user to select an answer from a drop-down menu. How can I achieve this? I've attempted the following code, but the select option isn't appearing on the screen. HTML: <div ...

Is it possible to trace the data flow in the console to see the destination when you submit a form on a website?

Can you track the destination of data when submitting a form on a website through the console? ...

Initiate events that are fetched through AJAX requests

Problem: Trouble arises when trying to extract data from an Ajax request that includes components for jQuery functions, and the jQuery functionality fails to work. Resolution: According to Bikash Waiba's response, this issue occurs because the jQuery ...

Utilizing Angular 6 mergeMap for handling nested API requests

My goal is to retrieve a list of clients along with their accounts using the observe/subscribe pattern. Each client should have a list of their accounts associated with their client id. This is how I attempted it: this.httpService.getClients().subscribe( ...

Display various DIV elements based on dropdown selection in Angular using ngModel

My webpage consists of three separate div elements: div1, div2, and div3. I am looking for a solution where div1 and div2 are displayed upon the first selection, div1 and div3 upon the second selection, and div2 and div3 upon the third and final selectio ...

What is the best way to use JavaScript to emphasize the searched text in a textbox?

My application uses JavaScript and I am looking to both highlight the search element and keep the cursor in the textbox positioned at the search item. Can anyone suggest a way to accomplish this using JavaScript? ...

Applying the Directive/Isolated Scope as Embedded HTML within an Angular-Bootstrap Popover

If you're using the angular-ui popover, you have the ability to include HTML content within it. However, I encountered some difficulties in placing a directive called sampleDirective inside the popover. Despite my attempts with the $sce.trustAsHtml an ...

The Viadeo Social Toolbox seems to be encountering technical difficulties at the moment

I attempted to utilize a Viadeo Social Toolbox, specifically the Viadeo Share Button, but it seems to be malfunctioning in certain browsers? I came across some outdated viadeo share URLs like this: http://www.viadeo.com/shareit/share/?url=${url}&title ...

Steps for making a Three.js 3D line collection with specified width and thickness

Is there a way to create a Three.js 3D line series with customizable width and thickness? Although the Three.js line object does have a linewidth attribute, it is not universally supported across all browsers and platforms in WebGL. Here is how you can s ...

Transmitting information through ajax json and encoding in php

I am transmitting stringify JSON data to my PHP file in the following format: [{"Country Code":"bob","Country":"503","Description":"bobby","\"Minute Rate":"oregon","USD\"":"","\"$5 Talk Time":"\r"},{"Country Code":"steve","Country":"70 ...

Troubleshooting problems with the width of a Bootstrap navbar

I'm encountering a frustrating issue with my bootstrap menu. When I include the "navbar Form" in the menu, the width of the menu extends beyond the screen width in mobile mode (when resizing the browser window or viewing on a mobile device). Interesti ...