Pages

Friday, March 4, 2011

getElementsByClassName


I came to know that IE does not support getElementsByClassName property of Javascript document object. I put around 12 hours on this to find.

I was writing a javascript for username and password textfield in which if onfocus value = "username" then insert "blank" value and onblur if textfield == "" then insert defaultvalue.

for that thing i was fetching the value with the help of property getElementsByClassName, it was working fine on firefox and other browser excepty IE. which was giving me error that "Object doesn't support this property" on google came to know that it doesn't support this property. then i approach jquery to solve this problem.

My html was like :


And the jquery which i write is like :

$(document).ready(function(){
$("input.name1").focus(function(){
if ($(this).val() == "username") {
$(this).val('');
}

});

$("input.name1").blur(function(){
if ($(this).val() == "") {

$(this).val('username');
}
});

});


May be this code is not very efficient. But i write it, whichever things came to my mind at that time. :)

No comments:

Post a Comment