Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in JavaScript when implementing input field shadow

I want to implement a shadow into an input field. This is the JavaScript code that I am 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 this error message:

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

Is there a bug into the code? How I can fix it?

like image 317
user1285928 Avatar asked Dec 12 '25 15:12

user1285928


1 Answers

there is something wrong with the ; maybe you pasted it from word or whatever but I see the error in FF

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

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

Edit: to use it in a function you simply wrap it with a function

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

then to call it, on document ready most likely

$(document).ready(function(){
    addListener();
});
like image 115
Huangism Avatar answered Dec 15 '25 07:12

Huangism