JavaScript How to make two tooltip ids independently close, and remember cookie?

I'm trying to make a tooltip using jQuery, with HTML and CSS. Each tooltip is different by the id and that works great, so I can make as many tooltips as I want and style them independently.

What I lack to understand is how can I make a tooltip to close, without affecting other tooltip(s). I'm using Regex Exp for cookies and all tooltips are on the same page.

Please note that #tooltip2 appears several time (4) on different locations on website, while #tooltip1 appears only once. If I click close on #tooltip2 I don't want it to affect #tooltip1, but to close all #tooltip2 divs. If I click close on #tooltip1, I want it only to close #tooltip1 divs.

Here is a part of code:

HTML:

<a target='_blank' href="javascript:;" class="tooltipMe no-print" id="tooltip1"><img src="images/icons/icon-tooltip-help.png" /><span class="tooltip-data">Tooltip 1 Text<span class="outerone"><span class="btn-close"><img src="http:/images/icons/icon-tooltip-close.png"  /></span></span></span></a></span>

<span class="tooltip-master"><a target='_blank' href="javascript:;" class="tooltipMe no-print" id="tooltip2"><img src="/images/icons/icon-tooltip-help.png" /><span class="tooltip-data">Tooltip 2 Text<span class="outer"><span class="btn-close"><img src="images/icons/icon-tooltip-close.png"  /></span></span></span></a>

jQuery

(function(){
    $('.tooltipMe').each(function(){
        var tooltip = $(this);
        var tooltipId = tooltip.attr('id');

        if( !getCookie(tooltipId) ) {
            tooltip.on('click.tooltipMe', function(){
                tooltip.addClass('hover');

                tooltip.find('.btn-close').on('click', function(){
                    var date = new Date();
                    date.setDate(date.getDate() + 1);
                  //tooltip.removeClass('hover').off('mouseenter.tooltip'); - in case we want to remove only tooltip
                  // Start of #tooltip1
                    $('.outerone > .btn-close').each(function(){ //code for #tooltip 1 - using 'each'
                        $('.tooltip-masterone > .tooltipMe').hide('fast'); //select what to hide and how
                    document.cookie = tooltipId + "=true; path=/; expires=Th, 31 Dec 2099 11:00:00 GMT;" + date.toUTCString();

                     function getCookie(name) {
        var matches = document.cookie.match(new RegExp("(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"));
        return matches ? decodeURIComponent(matches[1]) : undefined; // cookie solution with RegExp
    }
                    });
                  // #tooltip1 end line
                  // Start of #tooltip2
                    $('.outer > .btn-close').on('click', function(){ //code for #tooltip 2 - using 'click'
                        $('.tooltip-master > .tooltipMe').hide('fast'); //select what to hide and how

                    document.cookie = tooltipId + "=true; path=/; expires=Th, 31 Dec 2099 11:00:00 GMT;" + date.toUTCString();

                    });
                });
            });
        }
        else {
          tooltip.hide();
        }
    });

    function getCookie(name) {
        var matches = document.cookie.match(new RegExp("(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"));
        return matches ? decodeURIComponent(matches[1]) : undefined; // cookie solution with RegExp
    }})();

How can I make the tooltips close independently?

Answer:1

This is my first question on Stackoverflow so please excuse any mistakes I make. I'm trying to display in the view, some HTML from a template, which I use in the following directive: app.directive('...

This is my first question on Stackoverflow so please excuse any mistakes I make. I'm trying to display in the view, some HTML from a template, which I use in the following directive: app.directive('...

  1. html user insert image

I'm trying to open a remote video (let's say it's located at http://www.example.com/video.mp4) with the default Android player launched directly from Google Chrome, making use of the brand new intent:/...

I'm trying to open a remote video (let's say it's located at http://www.example.com/video.mp4) with the default Android player launched directly from Google Chrome, making use of the brand new intent:/...

  1. open video react native

This code works fine on IE, but fails on Chrome. Theory: When you click on the input, the input marks with an X or when you hit again the X is deleted (just like a checkbox) , when any of these ...

This code works fine on IE, but fails on Chrome. Theory: When you click on the input, the input marks with an X or when you hit again the X is deleted (just like a checkbox) , when any of these ...

  1. javascript code works with alert
  2. javascript code only works in debug
  3. how javascript code works
  4. javascript code only works with alert
  5. javascript code doesn't work
  6. javascript code doesn't work in chrome
  7. javascript code won't work
  8. javascript code dont work
  9. how javascript code coverage works

In a web application I have lists of things with the following structure: As you can see, when we list items (users, roles or anything basically), we have some associated actions on the right, ...

In a web application I have lists of things with the following structure: As you can see, when we list items (users, roles or anything basically), we have some associated actions on the right, ...

  1. accessibility links in tables
  2. accessibility for links