I am just beginning my journey with jQuery and would like to know how
the following could be summarised:

$(document).ready
(
        function()
        {
                $("fieldset input, fieldset select, fieldset textarea").focus
                (
                        function()
                        {
                                this.parentNode.className = "container on";
                                return false;
                         }
                );

                $("fieldset input, fieldset select, fieldset textarea").blur
                (
                        function()
                        {
                                this.parentNode.className = "container";
                                return false;
                         }
                );
        }
);

This code is used on a form. When a form element is selected, it
changes the classname of its parent (called "container") to "container
on" (this class has some css attached to it). When the form element is
de-selected, it changes the class name back to "container".

Notes:
1) The code is split onto different lines to help me with
visualisation because i am new to jQuery and am still getting used to
it.
2) Is there are shorter version of saying $("fieldset input, fieldset
select, fieldset textarea").
3) Is it really necessary to repeat the two functions - one for focus
and one for blur - or can they be joined?

Thanks everyone.
1) The way it is spread out on different lines is to help me visualise
what's going on.
2) The first area of summarisation i would

Reply via email to