Praveen Prasad
Praveen Prasad

Reputation: 32107

accessing jquery cloned element

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 ............
        });
    }

Upvotes: 0

Views: 221

Answers (2)

David Hellsing
David Hellsing

Reputation: 108490

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();
}

Upvotes: 0

Doug Domeny
Doug Domeny

Reputation: 4470

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.

Upvotes: 2

Related Questions