Display a string of text containing multiple interactive links

I have a table and I want to create an interactive effect where, upon mouseover or click of certain elements, text will appear next to it. This text may contain multiple lines and clickable links within the content.

For instance, in the table generated by the code below, hovering over 30 triggers the display of additional text:

<table style="width:100%">
  <tr>
    <th>First Name</th>
    <th>Points</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td><span title="monday: 10; tuesday: 10; wednesday: 10">30</span></td>
  </tr>
</table>

JSBin

However, I would like the text that appears to be displayed as individual lines such as monday: 10, tuesday: 10, and

wednesday: 10</code. Additionally, I need to make these lines clickable so that users can navigate to other sections or pages upon clicking. The current use of the <code>title
attribute does not support this functionality.

If anyone has suggestions on how to implement this feature using JavaScript, CSS, or any other method, please share your ideas.

(* this thread did not provide guidance on including clickable links in the appearing text *)

Answer №1

Experience the power of tooltips combined with links

Take a look at this JQuery example:

https://codepen.io/jamilhijjawi/pen/lIwbK

You can create simple and effective tooltips with links using tools like:

http://www.w3schools.com/css/css_tooltip.asp 

Answer №2

Consider this innovative approach that combines elements from both mshameer's answer and the provided bin.

For a practical demonstration, check out this Solution JSBin

This script offers two ways to create a tooltip. The first method involves declaring it in an HTML attribute using the '|' character as a line delimiter. The second method allows for directly passing the element and its tooltip as a JQuery object. This means you can fulfill your HTML-declaration desires without compromising on click styling requirements.

HTML:

<h1 data-over="You have hovered|Over this">Here is a title</h1> 

<p id="test">TEST</p>

JavaScript for searching by the data-over attribute:

// Search for text if it's simple in the HTML
var $dataElements = $("[data-over]");
$dataElements.each(function (index, el) {
  var $el = $(el);
  var text = $el.attr("data-over");
  if (text) {
    // Split by "|"
    text = text.split("|");
    createDataOver($el, text);
  }
});

JavaScript for manually adding a tooltip:

// Or provide it yourself.
var $testData = $(document.createElement("span"));
$testData.text("Click me.").click(function () {
  alert("Clicked");
});
createDataOver($("#test"), $testData);

The function createDataOver handles all the heavy lifting:

function createDataOver($el, data) {
  var $holder = $(document.createElement("div"));
  $holder.addClass("over hidden");

  // Check if we provided JQuery or a string array
  if (data instanceof jQuery) {
    // Make it relatively positioned
    $el.css("position", "relative");
    data.addClass("over-line");
    $holder.append(data);
  }
  else {
    data.forEach(function (line) {
      var $line = $(document.createElement("span"));
      $line.text(line);
      $line.addClass("over-line");
      $holder.append($line);
    });
  }

  // Append with the hidden class initially
  $el.append($holder);

  // Implement a closure with a timeout variable
  // To prevent immediate disappearance
  (function closure() {
    var timeoutCancel = -1;
    $el.mouseenter(function () {
      if (timeoutCancel !== -1) {
        clearTimeout(timeoutCancel);
        timeoutCancel = -1;
      }
      $holder.removeClass("hidden");
    });
    $el.mouseleave(function () {
      timeoutCancel = setTimeout(function () {
        if (timeoutCancel !== -1)
          $holder.addClass("hidden");
      }, 500);
    });
  }());
}

Caveats

This solution requires the parent of the tooltip to have position: relative. It does not have the same behavior as the title attribute regarding entry bounds – a display: block h3 element will react to mouseenter across its entire width. Given that the provided JSBin uses a table, this discrepancy may not be significant.

An effort has been made to manage timing issues by incorporating a half-second timeout on mouse leave. This enables users to hover back over the element within that timeframe to retain visibility rather than losing it immediately.

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

Kendo Grid with locked height

Using a grid with some elements locked, we have established a CSS-defined minimum and maximum height for the grid. .k-grid-content { max-height: 400px; min-height: 0px; } An issue arises when setting the height of the locked grid. If the grid&a ...

Is there a way to create a sequence where text fades in only after the previous text has completely faded out?

Currently, I am using JQuery to create a continuous slideshow of text values. However, after some time, multiple texts start to display simultaneously, indicating a timing issue. Even when hidden, the problem persists. My code includes 3 strings of text. ...

A widget for Windows 7 that can handle both HTTP GET and POST requests

I'm currently working on a small gadget for our intranet and have set up a PHP file on our server for initial testing purposes. Everything seems to be functioning properly when I use the GET request method, but I would prefer to utilize POST in order ...

Rearrange Material UI styles in a separate file within a React project

Currently, I am developing an application utilizing material-ui, React, and Typescript. The conventional code for <Grid> looks like this: <Grid container direction="row" justifyContent="center" alignItems="center&q ...

React-select-pagination is failing to retrieve data while scrolling

Struggling to load over 20,000 options using react-select from a Node API database? The page was barely loading until I implemented "react-select-async-pagination". However, there's a problem - the data is only fetched once. import React, { useRef, us ...

Steps to display selected value on another page

Presented below is the code snippet: <html> <head> <meta charset="UTF-8"/> </head> <body> <!--Text field area starts here--> <H3>My Surveys </H3> <hr> <br> <br> <br> <ol> < ...

Step-by-step guide on eliminating the modal post-validation

Newbie in reactjs looking for help with modal validation issue. Goal: Press submit button inside modal, validate, then close the modal. Want to reuse modal for another row. Problem: I'm having trouble making the function work for a new row after ...

Evaluating the Material ui Select element without relying on test identifiers

Currently, I am working with Material UI and react-testing-library to test a form. The form includes a Select component that is populated by an array of objects. import React, { useState } from 'react'; import { Select, MenuItem, FormControl, Inp ...

Guide on sending a JSON response from a POST request in JavaScript

After creating an API in Django that provides a JSON response based on a variable entered in the URL, I encountered a challenge with fetching and displaying this data using JavaScript. For instance, consider this URL: A sample of the JSON response looks ...

Angular.js: The $setDirty() method on a form does not automatically affect its child form elements

Currently, I am working on a form validation project using Angular.js. A specific challenge that I am facing is setting the dirty state on a child element of a form in an isolated scope within a directive. Does anyone know how to achieve this and set the i ...

Tips for utilizing New FormData() to convert Array data from an Object for executing the POST request with Axios in ReactJs

When working on the backend, I utilize multer to handle multiple file/image uploads successfully with Postman. However, when trying to implement this in ReactJS on the frontend, I find myself puzzled. Here's a sample case: state = { name: 'pro ...

Can you suggest an efficient method for routing with EJS templates on an Express server without constantly repeating code?

Assuming my app consists of two views: index.ejs and profile/index.ejs, I aim to set up routing using express code as shown below. /* GET home page. */ router.get('/', function (req, res, next) { res.render('index'); }); /* GET pr ...

Rows within distance

There seems to be too much space between the grid rows. I tried adding more photos or adjusting the height of the .image class to 100%, but then the image gets stretched out. The gap between items with classes .description and #gallery is too wide. When ...

Help with iterating over an array containing unique URLs, and set the `window.location.href` to each URL as we loop through the array

Do you have a question that needs answering? It may seem simple at first glance, but I've been struggling to find a solution. My goal is to create a PHP loop where the "$ad_id" varies each time the loop is executed. Then, I want to display a button ea ...

Using JavaScript to Parse JSON with Carriage Returns and Line Breaks

Utilizing the script below in JavaScript, I am able to extract a JSON string from a different JS file: // code to retrieve JSON data from another JS module var jsonMatch = data.match( /\/\*JSON\[\*\/([\s\S]*?)\/&bso ...

Seeking an efficient localStorage method for easy table modification (HTML page provided)

Currently, I am in the process of developing a custom 'tool' that consists of a main page with a menu and several subpages containing tables. This tool is intended for composing responses using prewritten components with my fellow colleagues at w ...

Utilize JavaScript to append a CSS class to a dynamic unordered list item anchor element

I am working with a list of ul li in a div where I need to dynamically add CSS classes based on the click event of an anchor tag. Below is the HTML structure of the ul li elements: <div class="tabs1"> <ul> <li class="active"> ...

I am interested in creating a ranking system in JavaScript using JSON data based on points

I have a desire to create the following: var users = {jhon: {name: 'jhon', points: 30}, markus:{name: 'Markus', points: 20}}; // I want it to return like this 1. Jhon with number of points: 30 // 2. Markus with number of points: 20 ...

Options presented in a horizontal line for convenient and quick

I need help with making my menu items responsive so they stay in one line without overlapping as the screen size decreases. Here is the code snippet I am currently using: <!doctype html> <html lang="en"> <head> <meta charset="utf-8 ...

The 'id' field was anticipating a numerical value, but instead received 'bidding'

When constructing a HTML page based on a model, I encountered an issue with a form that seems to be causing interference with the model being used for building the page. The error message I received is: Exception Type: ValueError at /bidding Exception Va ...