1

I'm pretty new to jquery and need some help.

I'm trying to clone a copy of the closest ancestor with class 'hidden' of $el and then look for $el's copy in the clone ancestor($hidden).

var $hidden = $el.closest('.hidden'),
    $substitute = $hidden
        .clone()
        .appendTo($hidden.parent());

Then I try to find $el's copy in $substitute. I tried this:

$substitute.find($el);

But it doesn't work..

Any help would be appreciated.

Tasos K.
  • 7,979
  • 7
  • 39
  • 63
odieatla
  • 1,049
  • 3
  • 15
  • 35
  • You can't. `$el` has nothing to do with a descendant of the cloned element. Apart from that `find` doesn't work that way. Logically you don't query for something that you already have. – Ram Feb 27 '14 at 02:04
  • you can try adding a data attribute to `$el` and then doing a `$substitute.find('[your-data-attrib]')` call. – Derek Feb 27 '14 at 02:11
  • Thanks @undefined . So is there a way that I can get the selector of $el and modified it and use the modified selector to get the cloned $el? I'm doing this is because I need to find .width() of $el but unfortunately $el is a descendant of a hidden element. Thanks very much! – odieatla Feb 27 '14 at 02:11
  • This might be relavant http://stackoverflow.com/questions/1472303/jquery-get-width-of-element-when-not-visible-display-none – Ram Feb 27 '14 at 02:17
  • Thanks @Derek ! Although $el.data("a","b") doesn't work well for my case which I believe it's due to the code base, I used addClass and it works now! Thanks for your inspiration! BTW, how can I vote up your answer? – odieatla Feb 27 '14 at 19:47
  • I'll add my comment as an answer for ya to vote up. – Derek Feb 28 '14 at 00:04

1 Answers1

1

You can try adding a data attribute to $el and then doing a $substitute.find('[your-data-attrib]') call

Derek
  • 4,575
  • 3
  • 22
  • 36