Displaying a div upon clicking a hyperlink

I am currently working on designing an unordered list that serves as a family tree. My goal is to enable users to click on each section, triggering the appearance of a new div in the center of the screen containing relevant details about that specific person. Additionally, I aim to create functionality where users can close this div by clicking outside of it.

While exploring various jQuery solutions, none seem to perfectly align with my requirements.

Below is what I have developed so far:

Fiddle

HTML:

<div class="tree">
    <ul>
        <li>
            <a href="chairman"><span class="accent">Chairman / Owner</span></a>

            <p>Name</p>

            <ul>
                <li>
                    <a href="financemanager"><span class="accent">Finance &<br>
                    Managing Director</span><span>Name</span></a>

                    <ul>
                        <li><a href="financeteam"><span class="accent">Finance
                        Team</span> <span>Name</span><br></a></li>

                        <li><a href="salesdirector"><span class="accent">Sales
                        Director</span><span>Name</span></a></li>
                    </ul>
                </li>
            </ul>
        </li>
    </ul>
</div>

CSS:

body {
    width:100%;
}

* {margin: 0; padding: 0;}

ul {
    line-height:20px;
}

.tree ul {
    padding-top: 20px; position: relative;

    transition: all 0.5s;
    -webkit-transition: all 0.5s;
    -moz-transition: all 0.5s;
}
...

<span class="accent">
...

Answer №1

Creating a popup with some simple javascript is surprisingly straightforward.

All you have to do is set up an onClick event for when the viewer clicks on a name in the list, triggering a javascript function that generates the popup. To make it visually appealing, consider adding some CSS styling to a designated class like .popup, then using innerHTML to create the popup content within that class. By centering and floating the .popup element above everything else, you can ensure it stands out. Utilizing javascript (or even better, jQuery) to detect any clicks outside of the popup will allow for easy closure.

If you'd like a basic example to follow along with, feel free to ask. Otherwise, this explanation should be sufficient for you to give it a try yourself - after all, practice makes perfect!

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

Automatically redirecting to a specific section upon clicking the textbox

I have developed a system where users can fill out forms and preview a PDF file. As they input information into the form, the PDF preview will update accordingly. Once all forms are filled out, users can generate a PDF of the completed document. I am look ...

Attempting to create a fixed div at a specific position, however, an unexpected Uncaught TypeError disrupted additional code functionality

Is there a way to make a div stay fixed in place while scrolling, but then unstick at a specific point? I found some code that seemed to work for this purpose, but unfortunately it caused an error that affected other jQuery scripts. The console displayed t ...

Is there a way to dynamically update the target of a form using JavaScript?

My goal is to change the target of a form in order to open a new window. However, all redirections of this form use the same window except for one specific button. This button calls a custom JavaScript function that needs to change the default "_self" targ ...

Tips for utilizing data attribute in jQuery programming

How can I modify my jQuery code to select the data attribute "data-price" instead of the value attribute? Sample HTML code: <span id="priceToSwap3"">$238</span> <select id="trapsize"> <option data-price="238">item1</option> ...

Looking to position content within a card to the bottom right in Bootstrap 4

Having trouble aligning my text and button within a card to the bottom right. Can't seem to get them to line up correctly. https://i.sstatic.net/OTDwJ.jpg This is what I have in my code: <div class="col-sm-3 text-right my-auto"> <div cl ...

My custom styles no longer seem to be applying after upgrading Angular Material from version 14 to 15. What could be causing this issue

Having some challenges with the migration from Angular 14 to Angular 15 when it comes to overriding material UI elements and themes. Looking for blog posts or documentation that can provide guidance on how to smoothly transition. Specifically, experiencin ...

Unable to access cross-domain ASMX Web Service on Internet Explorer 11 due to CORS restrictions

I am facing an issue with my ASMX Web Service - I can consume it from jQuery's $ajax in Chrome, but not in Internet Explorer 11. After learning about CORS limitations, I disabled it on the service by adding these lines to the web.config: <add nam ...

What is the process for altering fonts in a Chrome OS application?

After extensive research on the Internet, I have been unable to find clear instructions on how to modify the text font in a Chrome OS application. Most search results pertain to adjusting the font for the OS user rather than the developer of the app. My i ...

Having trouble with React image rendering using webpack?

Struggling to display an image in my React Web App, I encountered a broken image despite the correct file path appearing in the console log. We're utilizing url-loader and file-loader with webpack, importing the file path directly as necessary. Attemp ...

Use Ajax to send multiple inputs sharing the same name

How are you doing today? I have a snippet of code to share: <input name='uno[]' value='gonzalo' /> <input name='uno[]' value='marcos'/> <input name='uno[]' value='martin'/> < ...

Making the most of Material Design icons in MaterializeCSS: A step-by-step guide

I am looking to customize my mdi icons by adding my own set of icons into custom classes. The existing mdi classes do not match my requirements. Is there a way for me to add these icons and use them just like the default ones? <i class="mdi-image-face ...

Struggling to devise a for loop for a JavaScript-generated list

I'm attempting to loop the content of an H1 element through a list 10 times. I seem to have made a mistake in my code and would appreciate any guidance. var headOne = document.createElement("H1"); headOne.textContent = "Hello World"; document.body. ...

Error in Javascript when attempting to embed Redbubble

Hello, I am currently working on embedding the redbubble code into a Joomla site for a client who has a Redbubble store. However, I seem to be encountering some issues with the script. <script type="text/javascript" src="http://www.redbubble.com/asse ...

Password Reset Function Malfunctioning

Could somebody please assist me in resolving the issue with the reset email? When attempting to reset it, I received the following message: An email with further instructions has been sent. However, I did not receive a reset link. Here is the reset file. ...

The most efficient way to invoke a jws void method in the fewest steps possible

When calling a void method of a SOAP JWS web-service using JavaScript without expecting a result back, what is the most efficient and concise approach? ...

Fetching information through AJAX in NodeJS and saving it in a database

I am facing an issue with retrieving data from the client side in my NodeJS application. I have prepared JSON data on the client side, which can be viewed in this codepen link. On the server side, I am attempting to receive this data from the client: var ...

Mobile view causes malfunction in Bootstrap Toggle Burger Menu functionality

<nav class="navbar navbar-expand-lg navbar-dark px-2 " style="background-color:#E53935;"> <a class="navbar-brand" href="#">FoodFusion</a> <button class=&quo ...

Converting PHP arrays to JSON using jQuery: A step-by-step guide

Is there a way to store an array in a hidden div using php4 so that jquery can pick it up and convert it into a json object? I am attempting to send a data array to gmap in order to load multiple markers, but I'm struggling to pass a php array to jque ...

Ways to display a tooltip on a listbox that can be moved

My ASPX page contains the following control: <asp:ListBox ID = "X" runat="Server" CssClass = "listbox"></asp:ListBox> I need to display a tooltip on each list item, as they are movable and their positions can be c ...

Discovering the desired element within the added elements in order to trigger a click action

In an attempt to make the pause button function independently in each span element, I am facing a challenge. Whenever the user clicks the "add" button (code not provided), a new set of elements enclosed by <span class="emailform"> is appended to < ...