Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8949561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:14:50+00:00 2026-06-15T13:14:50+00:00

I have here a function that creates a tooltip, these tooltips are created on

  • 0

I have here a function that creates a tooltip, these tooltips are created on a page with infinite scroll (e.g. as soon as we hit the bottom of the page the function gets called again),maybe it’s worth mentioning that I am also using jScrollPane as a custom scroll, that gets reinitialized at the same time with my tooltip function.

The problem, is that every time the function is reinitialized, my tooltips get filled with multiple images at once, duplicates per every reinit on the infinite scroll callback.

this is the function:

function tooltipsInit() {

      //Setting the targeted elements variable
      var appliesTo = '.products .products-grid li .product-image-visible a, .featured .products-grid li .product-image-visible a, .new .products-grid li .product-image-visible a, .popular .products-grid li .product-image-visible a';
      jQuery(appliesTo).mouseenter(function() {
        jQuery(this).children('p').addClass('active');
        if((navigator.platform.indexOf("iPad") != -1) || (navigator.platform.indexOf("iPhone") != -1)) {
          //disabling the tooltips on iPad/iPhone
        } else {
          jQuery('body .wrapper').append('<div class="hcontainer"><div class="image"></div><div class="title"></div></div>');
          jQuery(this).children('img').clone().appendTo('.hcontainer .image');
          title = jQuery(this).children('img').attr('alt');
          jQuery('.hcontainer .title').append(title);
          jQuery('.hcontainer').fadeIn(200);

          function removeDuplicates() {
            //THIS IS MY QUESTION RELATED TO
            jQuery.removeData();
          }
          removeDuplicates();
        }
      });
      jQuery(appliesTo).mousemove(function(e) {

        offsetX = 235;
        offsetY = 175;

        windowHeight = jQuery(window).height();
        windowWidth = jQuery(window).width();
        ypos = 0;
        xpos = 0;

        if((e.pageY + 355) < windowHeight) {
          ypos = e.pageY + offsetY;
        } else {
          ypos = e.pageY - (offsetY + 30);
        }

        if((e.pageX + 455) < windowWidth) {
          xpos = e.pageX + offsetX;
        } else {
          xpos = e.pageX - (offsetX + 30);
        }

        jQuery(".hcontainer").css("top", (ypos) + "px").css("left", (xpos) + "px");
      });

      jQuery(appliesTo).mouseleave(function() {
        jQuery(this).children('p').removeClass('active');
        jQuery('.hcontainer').fadeOut(100).remove();

      });


    };

Like this I am clearing the entire DOM data (right?) and I get some Errors in Chrome dev tools.

Uncaught TypeError: Cannot read property 'nodeName' of undefined jquery-1.8.3.min.js:1719
jQuery.extend.acceptData jquery-1.8.3.min.js:1719
jQuery.extend.removeData jquery-1.8.3.min.js:1633
removeDuplicates custom-scripts.js:160
(anonymous function) custom-scripts.js:162
jQuery.event.special.(anonymous function).handle jquery-1.8.3.min.js:3344
jQuery.event.dispatch jquery-1.8.3.min.js:3058
elemData.handle.eventHandle

What can I do to select exactly the data that gets added to the DOM and delete only that?

like: removeData(mytooltipfunctionsData)

And also on the same topic, I am fairly new to Javascript/jQuery, how would you improve the function ?


EDIT

I’m stupid … I took a closer look at what you wrote there, and I was still running it inside a function that would get called … then I realized what you made there doesn’t require a function, because as you said, it’s event delegation :).

Thanks, IT WORKS! no duplicates and no errors on infinite scroll.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:14:51+00:00Added an answer on June 15, 2026 at 1:14 pm

    jQuerys removeData must be passed a DOM node, instead of a jQuery object.
    Instead of doing jQuery.removeData($(this)); for example, you need to do jQuery.removeData(this) or if you are using a selector, jQuery.removeData($('.selector')[0])

    about the duplicates, you might signal to your function if the current dom have been already initialized, like

    jQuery(appliesTo).each(function(){
       var $this = $(this);
    
       if (!$this.data('initialized')){ // skip in case it's been already initialized
         $this.data('initialized', true);
    
         $this.on({
           'mouseenter': function(){...},
           'mousemove': function(){...},
           'mouseleave': function(){...}
         });
       }
    
    });
    

    instead of removeData, IMO, you should be using off(), like $this.off() will remove all your bound events in the matched elements. Another way would be using event delegation, so you won’t need reinitialization, it will just work, for new and old elements, like this:

    var appliesTo = '.products .products-grid li .product-image-visible a, .featured .products-grid li .product-image-visible a, .new .products-grid li .product-image-visible a, .popular .products-grid li .product-image-visible a';
    
    jQuery(document)
    .on('mouseenter', appliesTo, function(){...})  
    .on('mouseleave', appliesTo, function(){...})  
    .on('mousemove', appliesTo, function(){...});  
    

    jQuery.on is the current prefered way of binding events or event delegation. The second way delegates, since jQuery(document) will always exist, regardless of any elements from appliesTo, any element that is added to the page will already have the elements bound, instead of manually initiating it every time (be it page load, ajax event, etc)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a function that creates a dynamic string array with dynamic string
Here I have a function that creates a string, assigns it to a string
Here I created a jquery function that gets css-color and creates element with background
I have a function that uses the Google Blobstore API, and here's a degenerate
Here's a brief rundown of my issue: I have a JavaScript function that gets
Here's the story... I have a jQuery function that does something, this function is
We have system here that uses Java JNI to call a function in a
I have the middleware that allows me to check user auth, here is: function
I have a quick question here. I know that the cakePHP find('first') function returns
Here is the situation. I have some javascript that looks like this: function onSubmit()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.