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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With