JSFiddle - React, Tailwind, and code Playground

by KomathiKarunakaran

HTML

<div class="test" placeholder="Type something..." contenteditable="true"></div>

CSS

.test {
    width: 500px;
    height: 70px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    padding: 5px;
}

.test[placeholder]:empty:before {
    content: attr(placeholder);
    color: #555; 
}

.test[placeholder]:empty:focus:before {
    content: "";
}

JavaScript

jQuery(function($){
    $(".test").focusout(function(){
        var element = $(this);        
        if (!element.text().replace(" ", "").length) {
            element.empty();
        }
    });
});