tags:

views:

36

answers:

2

iam doing something like this

    var _orgElm = $(this).clone(true);
    _orgElm.customResize();

    $.fn.custumResize = function() {
        return this.each(function() {
            // problem is here
            // when i apply this function an element, it reads width correctly. 
            //but when i do this on elements clone it reads zero is there is,
            // anyway i can read clone width also
            $(this).width();
            //some code here ............
        });
    }
+2  A: 

I suspect the problem is that the clone has not been added to the document yet. Try inserting it in the DOM and then get the width.

Doug D
yes, i also thought of that but later tried this$(this).css('width');
Praveen Prasad
I think Doug is right. You can not tell the dimensions of an object until it is put into the document. Why? Because other elements might affect the style. Make the element invisible, add it to the document and check the width then.
nickf
A: 

You have a typo (custumResize -> customResize), but you probably already know that.

Anyhow, try defining your plugin outside the ready event like this:

$.fn.customResize = function() {
    return this.each(function() {
        alert($(this).width());
    });
}

$(function() {
    var elem = $('.some-element');
    var clone = elem.clone();
    elem.customResize();
    clone.customResize();
}
David