What is the DOM blur() method in HTML?
Overview
In this shot, we will learn how to use the HTML DOM blur() method. In HTML DOM, if an element is a blur, it is not active or focused. The blur() method is only used in the <a> tag, and the link becomes a blur after the method is called.
Code
Code explanation
-
In line 7, we define a
<a>anchor tag for linkwww.google.comwith the IDmyAnchor, which we will use to get this element. -
In line 9, we have a button that will call the
getFocus()method in JavaScript. -
In line 10, we have another button that will call the
loseFocus()method. -
In line 13, we define the first function
getFocus()so that the element is in focus. -
In line 17, we define the second function
loseFocus()to make the element inactive, or blur the element with theblur()method.
Make sure to check the CSS file as well.
Output
We click the focus button to make the link active (focus) and click the Blur button to blur the link.