Dakifiz
Dakifiz

Reputation: 13

How to disable the blinking cursor in label

<div id="search">

    <input type="search" id="site-search"> 

</div>

How to hide blinking cursor after press enter?

Upvotes: 0

Views: 243

Answers (1)

Matthew Layton
Matthew Layton

Reputation: 42390

I agree with the sentiment of the comments, it's odd and not good UX, but since you asked...

The following code adds a keydown event listener to the input, and when the Enter key is pressed, it calls blur on the element:

const el = document.getElementById("site-search");
el.addEventListener("keydown", function(event) {
    if(event.key === "Enter") {
      el.blur();
    }
});

https://jsfiddle.net/aywpf0e4/

Upvotes: 1

Related Questions