Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display placeholder text on focus?

I have the following placeholder:

 <div class="input-text-container search" style="display:none;">
    <input type="text" id="textSearch" class="input-text-big search-message" placeholder="Search in your list"/>
    <i class="common-sprite cross search"></i>
</div>

The input is displayed when the user clicks on an icon with the class "search.icon-search"

I use the following JS code:

 $('.search.icon-search').on(
        'click',
        function(e) {
            e.preventDefault();
         $('#textSearch').focus()
        });

The problem is that the placeholder disappears on focus. How can I display it even on focus?

like image 283
Sarit Sara Avatar asked Sep 15 '25 11:09

Sarit Sara


1 Answers

You don't need any JavaScript or jQuery for this. I have a pure CSS solution. You can use an opacity on focus.

input {opacity: 0; outline: 0; border: 0;}
input:focus {opacity: 1; outline: 0; border: 0;}
span {border: 1px solid #999; display: inline-block;}
<span><input placeholder="This is not visible until you click!" /></span>
like image 112
Praveen Kumar Purushothaman Avatar answered Sep 18 '25 10:09

Praveen Kumar Purushothaman