Creating a tooltip using only Javascript (displaying/dismissing on click)

I am searching for JavaScript plugins, without using jQuery, that will help me create a basic tooltip feature.

What I want is to be able to click on an image and have a div appear below the image with some text inside along with a triangle in one corner. However, despite my efforts in searching on Google, I have not found anything that fits this criteria.

I am looking to make it so when the image is clicked, the information appears, and when the same image is clicked again, it should disappear. But I am struggling to figure out how to achieve this functionality.

Answer №1

If you're open to utilizing jQuery without relying on a plugin, achieving this effect is quite straightforward.

http://jsfiddle.net/RHW9C/

var isVisible = false;
$("#container").hover(function(){
    if (!isVisible){
        $("#popUp").fadeIn();
        $("#popUpText").fadeIn();
        isVisible = true;
    }
},function(){
    if (isVisible){
        $("#popUp").fadeOut();
        $("#popUpText").fadeOut(function(){isVisible=false});
    }
});

To trigger the action on click instead of hover:

http://jsfiddle.net/RHW9C/1/

var isVisible = false;
$("#container").click(function(){
    if (!isVisible){
        $("#popUp").fadeIn();
        $("#popUpText").fadeIn(function(){isVisible = true;});
    }
    if (isVisible){
        $("#popUp").fadeOut();
        $("#popUpText").fadeOut(function(){isVisible=false});
    }
});

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

The simplest method to make HTML elements inaccessible to the Simple HTML Dom Parser in PHP

Imagine a scenario where a basic web application is running and utilizing Simple HTML Dom Parser. The code snippet below demonstrates this: <?php include('simple_html_dom.php'); $html = file_get_html('http://someurl.com'); ...

Swapping the image source using a Vue dropdown menu

Recently I started using Vue and decided to implement a dropdown menu component (). The component pulls its list items from a JSON array structured as follows: <template> <div id="app"> <div id='container'> ...

How can I generate a list of separate words from innerText using JavaScript?

Wondering how to parse a string correctly using JavaScript? Take a look at the example below: <strong>word</strong>: or <em>word</em> or <p><strong>word</strong>: this is a sentence</p> etc... The objective ...

What could be causing the issue of undefined component props in Vue Router?

Recently diving into the world of Vue, I've been eager to master the art of utilizing Vue router. Smooth sailing with normal routing, I decided to spice things up by experimenting with dynamic routing. To my surprise, everything ran smoothly until I a ...

The raycaster in Three.js seems to be having trouble selecting the correct object

Hey everyone, I'm currently working on selecting objects using a raycaster and I want to change the material of the first selected object. Everything works smoothly until I pick the object - when I select the first element, only one object changes. I ...

Creating a responsive background image inside a div using Twitter Bootstrap

Is there a way to make the #bg image responsive, resizable, and proportional in all browsers? Sample HTML code: <div class="container"> <div class="row"> <div class="col-md-2"></div> <div class="c ...

Tips for Implementing Conditional Statements in SoundCloud API JavaScript Functions

Currently, I am attempting to retrieve a specific group of users by utilizing the SC.get() method within the SoundCloud API. My goal is to filter the resulting user set based on their follower_count falling between a range that I set. This follower_count d ...

PHP and MySQL pagination made easy with CSS styling

I am attempting to create a basic php pagination system, or more specifically, a css pagination system with php/mysql. Retrieving and storing data from the database while($row = $result->fetch_assoc()) { $id[]=$row["id"]; $name[]=$row ...

JkMegaMenu drop-down menus in Chrome are shifting to the left when the window is resized

Currently, I am utilizing the JKmegamenu plugin to incorporate a megamenu into a website that is currently under development. The megamenu functions properly and has an attractive appearance. However, there seems to be an issue where the drop-down divs shi ...

Ways to properly release file descriptors in write streams

I'm currently working on a code snippet that showcases what I'm aiming to achieve: const fs = require('fs'); var stream = fs.createWriteStream('/tmp/file'); stream.once('open', function(fd) { for (var i = 0; i ...

Dynamic elements fail to trigger JS function calls

I have a <div> that I dynamically populate with <input> and <a> elements using jQuery. It looks like this: The <div> gets filled when the addServicePanel() function is called: function addServicePanel() { var wrapper = $(".m ...

Unexpected response received from ajax call when supplying data to flot.js

Within this script block, I am retrieving data from a database in order to create a line graph. However, the data is returning as undefined and the graph is not being generated. var d; var arr = []; $(function() { var data; $.ajax({ da ...

Leveraging the power of PHP sessions within jQuery/HTML/Ajax

Following a successful login attempt, my PHP script initializes a session in the following manner: session_set_cookie_params(1800,'/','www.mydomain.com',true); session_start(); header("location:mainpage.html"); Now, I have ...

Enhancing Child Elements with CSS - Evaluating Rating Systems

Is there a way to change the opacity of certain images inside my div when hovering over them? Specifically, I want the 4th image and the first three to have an opacity value of 1. I've looked into using nth-child but am unsure how to implement it for ...

Angular 6 - Unlocking the Secrets of Filtered Results

I need help accessing the filteredArray in my .ts component. Currently, it is only accessible within the ng-container. <ng-container *ngIf="(userList | filter: 'name' : value) as filteredArray"> <tr *ngFor="let user of filteredArray ...

Moving images displayed on a webpage

Is animating 5 pictures/photos a simple task? Take a look at this example: Which programming languages are recommended for achieving this effect? Thank you Tea ...

Creating a User Interface for a Selenium script using Python: A Step-by-Step Guide

I recently developed a Python Selenium script for sending WhatsApp messages. I am now looking for a way to execute that script through a webpage. Can anyone provide guidance on how to achieve this? ...

What impact does the return value of jQuery's .not() have on the .hide() method?

I am encountering an issue with my HTML table and jQuery setup where rows are hidden when a user clicks on a specific topic, but I am uncertain about how it is functioning. Despite referencing the jQuery documentation, I am still confused about its behavio ...

Could anyone clarify the equation for me?

I recently came across a formula that has proven to be quite useful for my project. The code I'm referring to can be found at this link: (specifically the sphere version). Although I made some modifications to adapt the code to my own objects, the u ...

Problems with installing ambient typings

I'm having trouble installing some ambient typings on my machine. After upgrading node, it seems like the typings are no longer being found in the dt location. Here is the error message I am encountering: ~/w/r/c/src (master ⚡☡) typings search mo ...