Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to move tooltip on mouse move using javascript

const tooltip = document.querySelector('.toolhere + section');
window.onmousemove = function(e) {
  const x = (e.clientX + 3) + 'px',
    y = (e.clientY + 3) + 'px';
  for (var i = 0; i < tooltip.length; i++) {
    tooltip[i].style.top = y;
    tooltip[i].style.left = x;
  }
};
.toolhere {
  position: relative;
}

.toolhere+section {
  display: none !important;
  background-color: #ECECEC;
  color: #4D4E53;
  padding: 4px 8px 4px 9px;
  font-size: 12px;
}

.toolhere:hover+section {
  display: block !important;
  position: fixed;
}
<div class="items">
  <div class="sub-content">
    <div class="iconsize toolhere">
      <img src="pic.png" />
    </div>
    <section class="tooltip">this is tooltip</section>
  </div>
  <div class="sub-content">
    <div class="content-name toolhere"></div>
    <section class="tooltip">this is tooltip</section>
  </div>
</div>

I need some help here can anyone open to tell why its not working for me. Some kind of urgency. So what needs to be done or any changes needs to be done for the javascript. I’m able only hover the tooltip but tooltip doesn’t move on mouse move .

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The return value of querySelector is not an array,
cannot be traversed

Please use querySelectorAll instead

const tooltip = document.querySelectorAll('.toolhere + section');
window.onmousemove = function(e) {
  const x = (e.clientX + 3) + 'px',
    y = (e.clientY + 3) + 'px';
  for (var i = 0; i < tooltip.length; i++) {
    tooltip[i].style.top = y;
    tooltip[i].style.left = x;
  }
};
.toolhere {
  position: relative;
}

.toolhere+section {
  display: none !important;
  background-color: #ECECEC;
  color: #4D4E53;
  padding: 4px 8px 4px 9px;
  font-size: 12px;
}

.toolhere:hover+section {
  display: block !important;
  position: fixed;
}
<div class="items">
  <div class="sub-content">
    <div class="iconsize toolhere">
      <img src="pic.png"/>
    </div>
    <section class="tooltip">this is tooltip</section>
  </div>
  <div class="sub-content">
    <div class="content-name toolhere"></div>
    <section class="tooltip">this is tooltip</section>
  </div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading