Preventing Button Click with JQuery Tooltip

I've implemented a JQuery tooltip plugin on my website and it's working great. However, I'm facing an issue where I cannot click on the input button that appears when hovering over the tooltip. It seems like the button is not truly part of the DOM or gets removed instantly. I am unsure why the click event is not binding properly.

http://jsfiddle.net/BgDxs/126/

$("[title]").bind("mouseleave", function (event) {
        var evt = event ? event : window.event;

        var target = $(evt.srcElement || evt.target);

        evt.stopImmediatePropagation();

        var fixed = setTimeout(
            function () {
                target.tooltip("close");
            }, 200);

        $(".ui-tooltip").hover(
                    function () { clearTimeout(fixed); },
                    function () { target.tooltip("close"); }
                );
    });
$("[title]").tooltip({
        content: "...wait...",
        position: { my: "left top", at: "right center" },
        open: function (event, ui) {            
            var _elem = ui.tooltip;

            window.setTimeout(
                function() {                                            
                        var html = "<input type='button' value='Card Information' class='card_info_popup'></input>";

                        _elem.find(".ui-tooltip-content").html(html);
                    },
                200);
        },
        track: false,
        show: 100
    });


$('.card_info_popup').on('click', '.container', function() {
    alert('click');

});

Answer №1

Your implementation of event delegation needs a slight adjustment as the .container is not nested within your input element with the class card_info_popup. To correct this, consider using:

$('body').on('click', '.card_info_popup', function() {
    alert('click');
});

as opposed to:

$('.card_info_popup').on('click', '.container', function() {
    alert('click');
}); 

Discover the updated Fiddle here

Answer №2

modify:

$('.card_info_popup').on('click', '.container', function() {
    alert('click');

});

to

$(document).on('click', '.card_info_popup', function() {
    alert('click');    
});

Updated Fiddle

Answer №3

Give this a try.

To activate the click event on a recently generated tooltip button, you must utilize event delegation.

$(document).on('click', '.info_popup_card', function() {
    alert('clicked');

});

Answer №4

In order to properly handle the click event for a dynamically generated popup, you need to delegate it to a static element.

You can check out the changes I made in your JSFiddle here: http://jsfiddle.net/AbcDe/245/

Below is the updated code snippet:

$('body').on('click', '.ui-popover input.popup-info', function() {
    alert('Click event triggered');
});

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

Using CDN to load the STLLoader in Three.js

After deciding to have some fun by creating an STL loader, I've hit a roadblock. Despite trying various solutions found online, I'm still facing issues, mainly due to CDN errors. Currently, I'm following the tutorial on the Three.js site and ...

react tried to recycle markup error

Working on server-side rendering with React, encountering an error mentioned below. Here is the context: I have 2 React components, each stored in its own separate folder: - react-components - component-1-folder - component-1 - component-2-fo ...

Choose an item from my unordered list to automatically set the value of a form input

Hello, I am looking for a way to make a long Unordered list always visible on my website. I want users to be able to click on one of the List Items and have that item appear as the value in my Form type=text. I believe using Jquery would be the best way ...

Tips for effectively utilizing the Material-UI Grid component to implement this layout

Currently, I am working on incorporating this design in Material-UI by utilizing the Grid component. To better delineate the boundaries, I have marked the container border in red for clarity. The Add button should be positioned at the far right of the c ...

Utilizing jQuery's .slidedown alongside Prototype's .PeriodicalUpdater: A Comprehensive Guide

I am currently working on creating an activity stream that automatically updates with the latest entries from a database table every time a new row is added. Right now, I am using Prototype's Ajax.PeriodicalUpdater to continuously check for new entri ...

The moving div suddenly halts before continuing its journey

Two overlapping divs create an interesting sliding effect. A gray div slides in from the top over a black div. Hovering your mouse over the black div causes the gray one to slide out of view. If you hover over the gray div, it also slides out but pauses ...

I will design a photo gallery on my website with distinct albums showcasing a multitude of captivating images

I am looking to develop a feature on my website that will allow users to create image galleries for each profile. Users should be able to upload multiple pictures and organize them into albums. However, I am unsure of how to approach building such function ...

Performing an AJAX GET request to the API after a set time interval

The API is constantly updating with live values, so I am attempting to fetch the data every second and display it on the webpage. Although I used a GET request call every N seconds using set_interval(), the values only load once and do not update with eac ...

Executing JavaScript code within ASP.NET Visual Basic

My current web application uses jQuery and JavaScript, but I want to add more features that are supported in ASP.net VB. However, I am unsure if the JavaScript can run after the VB code. Essentially, I would like the web app to follow this sequence: ...

Using the map function twice in React Native causes a rendering issue

<View style={styles.card} > {store.crud.list.map(function(element, index){ return ( <View style={styles.wrapper}> {element.map(function(number, index){ return( ...

Submitting data through a PHP server-side script

I am facing a dilemma regarding why the form is not submitting and directing me to the index.php page. Being new to PHP, I am attempting to utilize the User object. Below is my current progress: <main> <header> <h1>Cr ...

Leveraging JS Variables within Twig Template

I am trying to incorporate a JavaScript variable into Twig. Despite attempting to implement the solution mentioned here, my code below does not render the map properly. If I remove the part between "var polylineCoordinates" and "polyline.setMap(map);", th ...

What is the process for transferring a file to a different directory?

<html> <head> <title>Main Page</title> </head> <body> <h2>Main Page</h2> <form method="post" action="index.php" enctype="multipart/form-data"> <input type="file" name="filename"> <input type=" ...

Decoding JSON with HTML in c#

While serializing an object into JSON that contains HTML, I encountered a unique issue. Below is the structure of my class: [Serializable] public class ProductImportModel { public string ProductName { get; set; } public string ShortDescription { get; ...

When attempting to use the ResponsiveSlides plugin, the functionality of 'Image links' seems to be disabled in the Chrome browser

While everything is functioning perfectly in Firefox and IE, I've encountered an issue with Chrome. It only works after right-clicking and inspecting the element; once I close the Inspector, it stops working - displaying just an arrow cursor as if the ...

Encountering a 403 Forbidden error while attempting to make an Ajax post request within the Django

Struggling to implement jQuery in a Django framework web application? Having difficulty getting a simple ajax call to function properly? Here is what my template file consists of, containing the form HTML and JavaScript to manage the ajax call: <script ...

Decoding a JavaScript object when receiving it as JSON through a POST request

While browsing through various SO posts, I came across the statement "javascript is JSON". However, I am struggling to apply this concept in my application. My issue arises when I try to perform a POST request using jQuery. $.ajax({ type: &apo ...

Having trouble retrieving textfield value with jQuery

On my website, I have an invoice.jsp page that requires jQuery to calculate values in textboxes. Within the invoice, there is a quantity textbox. When a user enters a quantity, the price should be dynamically calculated as (total_subPrice= unit_price * qu ...

What is the best way to incorporate Express following an asynchronous function?

After setting up my Firebase and initializing it, I managed to retrieve data from it. However, I encountered an issue when trying to use express.get() and json the data into the server. I'm unsure of what the problem could be. let initializeApp = requ ...

Obtain Phonegap Build CLI-5.2.0 and Close Directly from a Web Application

Struggling with integrating window open calls in my app using inappbrowser. Essentially, I am utilizing phonegap to wrap a mobile skinned CMS site with special app functionalities. Here is the snippet from index.html where I am deploying inappbrowser (wit ...