R
R
Rasul Gitinov2017-08-21 22:53:26
css
Rasul Gitinov, 2017-08-21 22:53:26

How to track clicks on a specific element?

There is a map with location points on it. All points have the same general class "mark". I'm trying to make it so that when you click on a dot, the "active" class is added to it and the subtab appears. Here is the code:

$(function(){
  $('.mark').click(function(){
    if($('.mark.active').length < 1){
      $('.mark').addClass('active');
      $('.tooltip').fadeIn();
    } else {
      $('.mark').removeClass('active');
      $('.tooltip').fadeOut();
    }
  });
});

Everything seems to work, but only when you click on one point, all points are activated. How can I make it understand that I am clicking on a specific element?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivan Bogachev, 2019-04-23
@alexanderkonovalov56

.category-desc {
    position: relative;
}

.page-header.item-title {
    position: absolute;
    bottom: 60px;
    left: 10px;
}

R
Robert Bl, 2017-08-21
@raselgit

event.target

K
kulaeff, 2017-08-21
@kulaeff

You can use e.target or this:

$(function(){
  $('.mark').click(function(){
    var $mark = $(this); // или $(e.target)

    if(!$mark.hasClass('active')) {
      $mark.addClass('active');
      $('.tooltip').fadeIn();
    } else {
      $mark.removeClass('active');
      $('.tooltip').fadeOut();
    }
  });
});

Can be redone using .toggleClass()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question