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?
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();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With