Home > Web Front-end > CSS Tutorial > How Can I Remove Placeholder Text on Focus in Chrome?

How Can I Remove Placeholder Text on Focus in Chrome?

Patricia Arquette
Release: 2024-11-18 08:15:02
Original
507 people have browsed it

How Can I Remove Placeholder Text on Focus in Chrome?

Removing Placeholder Text on Focus with CSS or jQuery

When entering text into a text field, placeholder text typically disappears to make way for the user's input. While most browsers do this automatically, Chrome does not.

CSS Solution

To specifically target Chrome, you can use the input:focus::placeholder selector:

input:focus::placeholder {
  color: transparent;
}
Copy after login

This CSS rule sets the placeholder text to transparent when the input field is in focus.

jQuery Solution

You can also achieve this with jQuery:

$("input").on("focus", function() {
  $(this).attr("placeholder", "");
});

$("input").on("blur", function() {
  $(this).attr("placeholder", "Type something here!");
});
Copy after login

This jQuery code sets the placeholder text to an empty string when the input field is in focus and restores it to the desired text when the field loses focus.

Browser Support

UPDATE:

All modern browsers now support hiding placeholder text on focus using the input:focus::placeholder CSS selector. Therefore, the jQuery solution is no longer necessary.

The above is the detailed content of How Can I Remove Placeholder Text on Focus in Chrome?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template