jQuery event binding does not work properly or i can't make it properly working

Posted by Saiful on Stack Overflow See other posts from Stack Overflow or by Saiful
Published on 2010-05-21T05:35:00Z Indexed on 2010/05/21 5:40 UTC
Read the original article Hit count: 213

Filed under:
|
|
|
|

HTML:

<input id="email" name="email" type=text />
<input id="password name="password" type="password" />

JavaScript:

var fields = ["email","password"];
for (var i in fields) {
    var field = $("#"+fields[i]);
    field.bind({
        focus: function() {
            field.css("border-color","#f00");
        },
        blur: function() {
            field.css("border-color","#000");
        }
    });
}

My desire action will be as follows:

  1. When I place cursor on any of the above fields the input field's border will be red.
  2. When I take away the cursor from the field it's border will be black.

But the event is occurs only for the password filed whether I place and take away cursor form any of the above fields.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery