Modify the information within several div sections

Is there a way to update the content inside two divs simultaneously when a button is clicked? Specifically, I want to change the bio in one div and the picture in another based on the selected player. Currently, when the button is pressed, it only loads the same content in both divs.

<section id="container">
    <div id="playerMenu">
        <nav>
            <h3>Choose a Player</h3>
                <ul>
                    <li><a href="adnan"  >Adnan Januzaj</a></li>
                    <li><a href="movie-2">Movie 2</a></li>
                    <li><a href="movie-3">Movie 3</a></li>
                </ul>
        </nav>
    </div>


    <article class="playerPic">
        <section id="picture">
                <div id="adnan1">
                        <img src="images/januzaj.png"/> 
                </div>  
    </article>


        <div class="playerBio">
            <section id="content">
                <div id="adnan">
                    <p>      Bio for Adnan Januzaj Goes Here</p>
                </div>
        </div>

            </section>
        </section>
</section>

    <script type="text/javascript" charset="utf-8">
        $(document).ready(function(){

            $('#playerMenu ul li a').click(function(){
                $('#content').load('players.html #' +   $(this).attr('href'));
                return false;
            });

            $('#playerMenu ul li a').click(function(){
                $('#picture').load('players.html #' + $(this).attr('href'));
                return false;
            });

        });
    </script>

All data and images are being fetched from a separate HTML file named players.html

<div id="adnan">
<h2>Adnan Januzaj></h2>
<p>Bio for Adnan Januzaj Goes Here.</p>


<div id="adnan1">
<img  src="images/januzaj.png"/>
</div>
</div>


 <div id="movie-2">
<h2>Phil Jones</h2>
    <img  src="images/jones.jpg"/>
<p>Bio for Phil Jones Goes Here.</p>
 </div>

I'm wondering if it's possible to achieve this functionality. While I am able to modify one div's content, can a single button selection lead to changes in content within 2 divs? Can a navigation button contain multiple URLs?

Thank you!

Answer №1

To incorporate both modifications into a single event listener, combine them like this:

 $('#playerMenu ul li a').click(function(){
    $('#content').load('players.html #' +   $(this).attr('href'));
    $('#picture').load('players.html #' + $(this).attr('href'));

    return false;
  });

Answer №2

Don't forget to include the number 1 after the href tag in your javascript code.

Javascript

$('#playerMenu ul li a').click(function(){

    $('#content').load('players.html #' + $(this).attr('href'));
    $('#picture').load('players.html #' + $(this).attr('href') + '1'); /* make sure to add the 1 */

    return false;
  });

It would be helpful to give more descriptive IDs to your divs, such as "adnan-bio" and "adnan-pic", and then append these to each href when calling load.

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

"JavaScript/jQuery: The pattern in the text does not align with the string

I am currently working on validating a text field with the specific data pattern of "I-MH-ABCD-ABC-1222". Below is the regular expression I have implemented, but unfortunately it is not functioning as intended. var router_added_sap = "I-MH-ABCD-ABC-1222" ...

Instead of logging an "Error" message along with a stack trace, log a "Warning"

If I were to utilize new Error() or new TypeError(), the resultant stack trace would resemble the following: Error: Live-Mutex client lock request timed out after 6000ms I am curious if there exists a method to create a message that commences with "Warni ...

Looking to obtain rendered tree data upon page load?

Is there a way to retrieve all rendered tree metadata when the page loads using jstree? I'm looking for an output similar to this: [23,24] Please note that I would like to have each id stored in the metadata object displayed as [23,24] upon page loa ...

What is the method to extract a value from the $emit payload using Vue.js?

I have a situation where I am sending an event with different values from my ConversationList component (child) to the ConversationModel component (parent). Conversation List getConversation(conversation_id, receiver_id, username, avatar){ this.$emit(& ...

Discover the secrets of extracting the ID from a MenuItem within a Menu

Table Ui with menu Struggling with fetching the correct user ID in the edit button The edit button for all users is only displaying the last user's ID If the edit button is not nested inside the Menu, it works fine. However, within the Menu, it onl ...

jQuery + Pyramid: A Dynamic CAPTCHA Solution

Seeking guidance on utilizing CAPTCHA with jQuery and Pyramid as the back-end (minus PHP). Can this be achieved? Appreciate any insights! ...

What is the optimal method for incorporating sass/scss into a React application?

After reviewing the create-react-app documentation, it seems that they recommend using node-sass. However, the package on npm indicates that LibSass and Node Sass are deprecated. Can anyone provide guidance on the most effective method for installing Sas ...

Executing multiple functions with onPress in React Native

When I press onPress using TouchableOpacity, I am attempting to invoke multiple functions. Here's an example: functionOne(){ // perform an action } functionTwo(){ // execute something } <TouchableHighlight onPress{() => this.functionOne()}/& ...

I am encountering difficulties displaying the image and CSS files from another folder in my HTML with Node.js

I am facing difficulty in establishing a connection between my front-end and back-end using node.js. As a result, the website only displays the HTML code without linking to the CSS or image files. Here is the folder structure: root -src •pi ...

Get the PDF document via FTP by utilizing an XMLHttpRequest and a generic handler

Attempting to download a PDF file from an FTP server using a JQuery Ajax request. The reference used was found at . Below is the Jquery ajax call being made: $.ajax({ xhr: function () { var xhr = new window.XMLHtt ...

When I click away from the screen, the bottom border of the button disappears

view my fiddle Here is the HTML code snippet I am working with: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> <button> <i class="fa fa-5x fa-motorcycle gobumpr_icon"></ ...

NodeJS Error: Attempting to access 'json' property from an undefined source

I'm in the process of setting up a CronJob to make an API call and save the response into the database: const CronJob = require("cron").CronJob; const btc_price_ticker = require("../../controllers/BtcExchange/Ticker"); const currency = require("../.. ...

Discovering the difference between a singular array and an array of arrays

x = [1, 2,3, 5]; y = [1, [2], [3, [[4]]],[5,6]])); I am currently facing a challenge in finding the difference between these two arrays. function findArrayDifference(arr1, arr2) { var tempArr = [], difference = []; for (var i = 0; i < arr1.l ...

Simplified method of connecting dynamic components without needing to remember functions in jQuery

I have a page where users can freely move, resize, and modify content. The basic setup is as follows: $('.element').on().resizable().draggable(); When this code is called on page load, it allows elements to be resizable and draggable. The issu ...

Refresh the page before the conclusion of the express-Node js function

I am encountering an issue with a function that functions properly with small files but fails when dealing with large files. The problem occurs when the axios post request in Express JS ends, causing a page refresh. I am using React JS on the client side a ...

Issue with Material UI select element not updating in onChange event of a dynamic form

Currently, I am developing a dynamic form that requires loading extra fields through JSON. However, I am facing a problem as the <Select> and <Radio> elements are not re-rendering after the value is changed. The form itself is a functional comp ...

What is the best way to mention @here with an attachment?

I'm attempting to use the canvas say command to display an image with an @here mention included, but unfortunately it only shows the image without making the mention. Below is what I have attempted: message.channel.send(`@here\n`+attachment); ...

Is there a way to create optional sections within a reusable component's template in a Vue 3 application?

Recently, I've been immersed in developing a Single Page Application (SPA) using the powerful combination of Vue 3, TypeScript, and integrating The Movie Database (TMDB) API. One interesting challenge I encountered was with my versatile movie card co ...

I am having trouble displaying the background on my website using css/html

I'm currently working on enhancing my website BJBGaming1.com, and I've encountered an issue with setting a background. Here's the code snippet I have: <!doctype html> <html class="no-js" lang="en"> <head> <meta charset= ...

What is the best method to display a tooltip for a disabled radio button within a set of radio buttons?

Is there a way to disable a specific radio button based on a condition and display a tooltip only for that disabled button? https://i.stack.imgur.com/niZK1.png import {Tooltip} from '@mui/material'; <Tooltip titl ...