Is it possible to nest multiple events in javascript?

As a newcomer to JavaScript, I find this function intriguing, though I’m not entirely sure why it’s designed the way it is. At times, it seems to achieve its intended purpose of keeping the div visible and in the same position when clicking another div, until clicking back on the original one. However, I’m puzzled by the intermittent behavior where the messages “The second click has been made =” and “The first click has been made = ” are printed seemingly as if the if conditional is not being respected, even when only one click is made. Despite this confusion, I appreciate that the function appears well-designed and capable of fulfilling its objective under certain conditions.


**JavaScript**

`let clickFuera = true;

function inOutHover(idDivCard, isHover, idPoligono) {
  const divCard = document.getElementById(idDivCard);
  const poligono = document.getElementById(idPoligono);

  const manejadorEventoMovMouse = function (e) {
    divCard.style.left = e.pageX + 40 + "px";
    divCard.style.top = e.pageY + 5 + "px";
  };

  const manejadorEventoClick = function () {
    if (clickFuera) {
      document.removeEventListener("mousemove", manejadorEventoMovMouse);
      divCard.manejadorEventoMovMouse = null;
      divCard.style`your text`.display = "block";
      clickFuera = false;
      console.log("The first click has been made  = " + clickFuera);
    } else {
      poligono.removeEventListener("click", manejadorEventoClick);
      divCard.style.display = "none";
      clickFuera = true;
      console.log("The second click has been made = " + clickFuera);
    }
  };

  if (isHover) {
    divCard.manejadorEventoMovMouse = manejadorEventoMovMouse;
    document.addEventListener("mousemove", divCard.manejadorEventoMovMouse);
    poligono.addEventListener("click", manejadorEventoClick);
    divCard.style.display = "block";
  } else {
    if (divCard.manejadorEventoMovMouse) {
      document.removeEventListener("mousemove", divCard.manejadorEventoMovMouse);
      divCard.manejadorEventoMovMouse = null;
    }
    divCard.style.display = "none";
    poligono.removeEventListener("click", manejadorEventoClick);
  }
}


**HTML**

<body>
  <div id="poligono" class="poligono" onmouseover="inOutHover('divCard', true, 'poligono')" onmouseout="inOutHover('divCard', false, 'poligono')"></div>
  <div id="divCard" class="divCard">This is a card</div>

  <script src="script.js"></script>
</body>


**CSS**

body {
  font-family: Arial, sans-serif;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f0f0f0;
  margin: 0;
}

.poligono {
  width: 100px;
  height: 100px;
  background-color: #3498db;
  cursor: pointer;
}

.divCard {
  display: none;
  position: absolute;
  background-color: #fff;
  border: 1px solid #ccc;
  padding: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

I’ve attempted to review the code and ensure that the events are properly executed, but I’m still perplexed by the inconsistent behavior. Sometimes it seems to work as expected, while other times it doesn’t. It’s been a challenge to pinpoint the exact reason behind this variability. Despite my efforts to understand and debug the code, I’m left wondering why it functions correctly on some occasions but fails to do so on others.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật