I have following code:
$('body').on('mouseenter', 'label', function(){
if(this.offsetWidth < this.scrollWidth){
if(!this.getAttribute('title')) {
this.setAttribute('title', this.innerHTML);
}
}
else{
this.removeAttribute('title');
}
});
But in my project we need to have less dependencies with jquery. So i need to rewrite on('mouseenter') method. I tried something like this:
var matches;
(function (doc) {
matches =
doc.matchesSelector ||
doc.webkitMatchesSelector ||
doc.mozMatchesSelector ||
doc.oMatchesSelector ||
doc.msMatchesSelector;
})(document.documentElement);
document.addEventListener('mouseenter', function (e) {
if (matches.call(e.target, 'label')) {
if (this.offsetWidth < this.scrollWidth) {
if (!this.getAttribute('title')) {
this.setAttribute('title', this.innerHTML);
}
}
else {
this.removeAttribute('title');
}
}
}, false);
But it doesn't work, cause it firing only once ( on mouseenter on document ). I can't get all elements with tag label and add event listener to them, cause i have many labels in different parts of my application. Is this possible to get full equivalent of jquery function?