I have an textarea on a webpage, and I want to have a border around it when the string is empty. But it only works if I put something into the text and then delete it again. How can I make the border visible before I write in the textarea? Here is the code:
$("#message-box").on("keyup", function(){
var charCount = $("#message-box").val().length;
console.log("charCount");
$("#char-count").html(charCount);
if (charCount === "") {
$("#message-box").css("border", "10px solid red");
}else{
$("#message-box").css("border", "");
//event listener
$("#submitbutton").on('click', function() {
var comment = $("#message-box").val();
$("#visible-comment").html(comment);
$("#message-box").hide();
console.log(comment);
return false;
});
};
};