Monday, August 15, 2011

jQuery tips & tricks

jQuery tips and tricks:-

I am new in jquery but there are several things i learnt during implementation of jQuery into projects (asp.net MVC).

1. Disable vs Readonly:-
we can not send Disable controls value to server so for this purpose, we have readonly property and as it is the part of jQuery so it is control independent property.
$("#txtName").attr("readonly","readonly");
$("#txtName").removeAttr("readonly");

2. each vs chaining

we have 2 option to associate a particular action to set of controls returned by selector
a) use Intrator method to assign action to each value or
$(".txtbxClass").each(function(index){ $(this).click(function (){ this.value+="txtbxClass";}););

b) we can use chaining and assign all actions in a single statement.
$(".txtbxClass").click(function (){ this.value+="txtbxClass";});
Both statement will work in similar way!!!!!!!!!!
but the second option is more clean code and easy to understand.

3.

No comments:

Post a Comment