Reputation: 25
Is it possible to use the blur
event on a text instead of an input? If so, how do I achieve that using vanilla JavaScript? I've searched a lot but I can't find the answer I'm looking for.
Upvotes: 2
Views: 294
Reputation: 5777
It is possible if you add a tabindex
to the text element
var p = document.getElementById("test");
p.addEventListener("focus", function(e) {
e.target.style.color = "red";
});
p.addEventListener("blur", function(e) {
e.target.style.color = "";
});
<p id="test" tabindex="0">Test</p>
Upvotes: 3