Home > Software engineering >  How can select the tag name with the postion of mouse?
How can select the tag name with the postion of mouse?

Time:09-28

I can get selected the html tag with the position of mouse ?

when i move with the mouse i can update for exmpel the border of tag in the position of mose .

CodePudding user response:

You can use mouseover event and get the event.target.

document.body.addEventListener('mouseover', (event) => console.log(event.target), false);

CodePudding user response:

You can use mouseover event on document and then can get tag name as below:

$(document).mouseover(function(e){
     let tagName = e.target.nodeName;
     //you can also get class in this as below
     let tagClass = e.target.className;    
});

Then you can add css on class/id or tag.

  • Related