0

I have the following code:

var options = [
    '#content',
    'h5'                     
];

var elements = [];

for(a in options){
    elements[a] = {
        'handle':  $(options[a]),
        'ref_copy': $(options[a])
    };

    elements[a].handle.hover(
        function(){
            elements[a].handle.css(
                'border', '1px dashed red'
            );
        },
        function(){
            elements[a].handle.css(
                'border', elements[a].ref_copy.css('border');
            );
        }
    );
}

Why does it make the border of the element red.. but when I call elements[a].ref_copy it isn't converting back?

EDIT://

Why do I have to do this:

            var options = [
                '#content',
                'h5'                      
            ];

            var elements = [];

            for(a in options){
                elements[a] = {
                    'handle':  $(options[a]),
                    'ref_copy': new Object
                };

                elements[a].ref_copy = elements[a].handle.clone(); 

                elements[a].handle.hover(
                    function(){
                        elements[a].ref_copy = $(this).clone(); 
                        $(this).css(
                            'border', '1px dashed red'
                        );
                    },
                    function(){
                        $(this).css(
                            'border', elements[a].ref_copy.css('border')
                        );
                    }
                );
            }

What are the mechanics here?

4

0 回答 0