Search code examples
jqueryvariablesappendclone

jQuery find and append element


I created a variable to find 'img' and clone like this:

var element = jQuery.find('img').clone();
element.appendTo('body');

It doesn't work for me. My Chrome console tells me:

Uncaught TypeError: Object [object Array] has no method 'clone'

Is it even possible to write jQuery.find() like that? What else can I try?


Solution

  • find() requires a starting point which you haven't provided. Syntax of jQuery.find() is incorrect. Proper syntax for find() is :

    jQuery(parentSelector).find(descendentSelector);
    

    This will search within the parentSelector for the descendentSelector.