Clone an element

Hello. I’m trying to clone an element and doing an alert to see what was cloned.

$(".the-names").live("click", function(){
    var name = $(this).clone();

but in the alert i get : [object][Object]


referring to:

<input type='text' class='the-names' value='$salute $fname $lname' readonly>

what I’m gonna do is clone the text box and append it somewhere. so is the code cloning the text field?

Alert boxes only allows strings therefore all you will see is the typeof which in for a DOM element is object, if you need to debug your code you will need to use either Chrome’s, Opera’s, Firefox’s or Safari’s developer tools which you can learn more about at the below link.

Then what you will want to do is replace alert with console.dir which dumps the object to the console in the developer tools.

$(".the-names").live("click", function(){
    var name = $(this).clone();

Or Internet Explorer’s developer tools.

Firefox was the last browser to get the developer tools built in instead of as an extension.

So it really doesn’t matter which browser you use as they all understand the console object and have developer tools that provide access to the console to see what the call wrote.