JavaScript error while implementing input field shadow

I want to implement a shadow in an input field. This is the JavaScript code I'm using:

<!-- input field shadow  -->
var placeholder = "test field"
$("input").on({
    focus: function() {
        if (this.value == placeholder) {
            $(this).val("").removeClass("shadow");
        }
    },
    blur: function() {
        if (this.value == "") {
            $(this).val(placeholder).addClass("shadow");
        }
    }
}).trigger("blur");โ€‹    

When I run the code in Firefox, I get the following error message:

illegal character}). trigger ("blur");

Is there a mistake in the code? How can i fix this?

+3
source share
2 answers

something is wrong with; you may have inserted it from a word or something else, but I see an error in FF

Delete and any spaces after it then enter it again, it will get rid of the error

Edit: I think the spaces or tabs are behind; but to do the above, the error will disappear

Edit: use it in a function that you just transfer using the function

var addListener = function(){
    // your code here
};

then for his call, most likely, ready for the document

$(document).ready(function(){
    addListener();
});
+3

, jQuery 1.6.4, .

jQuery 1.7.1

+3

All Articles