What is $("this")? Nothing. It should be $(this) which is a reference to the element that invokes the current function, that is the button. But if you mean to change the color of the invalid element say the ffname textbox, then it should be
ffname.css("background-color" , "red");
See
demo[
^]
++++++[Last Round]+++++
You code is a mess, did you write it yourself? Do you understand the code? If not, you should consider some tutorials to equip yourself with the necessary knowledge, else no amount of explanation can help you.Start from the basic and learn one thing at a time. At a last bit, I have put together a small example. The rest is up to you to figure out.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#sub").click(function(){ //submit btn
var ffname = $("#fname1"); //fisrst name
if(ffname.val() ==""){
ffname.css("background-color" , "red");
}
else
{
ffname.css("background-color" , "green");
}
// to prevent default action and propagation.
return false;
});
});
</script>
</head>
<body>
<form method="post">
<p>
Fisrt Name:
<input id="fname1" class="input" type ="text"/>
</p>
<button id="sub" class="btn-danger">Save </button>
</form>
</div>
</body>
</html>
Good luck.