mardi 5 juillet 2016

How can I make my Jquery conditional?

I am trying to use jquery to change the border color of an element when it is not empty. From what I've looked up everything seems right, but I still can't seem to get it to work.

Here is my JS fiddle: http://ift.tt/29jYULz

HTML

Text <input type="text">
<button>Click Me</button>

JQuery

$("button").on("click",function(){
    if($("[type='text']").val() == null){
        $(this).css("border","2px solid red");
    } 
});

Aucun commentaire:

Enregistrer un commentaire