Take the 2-minute tour ×

This is sort of a hypothetical question -- what I'm actually doing is not changing the color of an element -- I've been trying to figure out what is happening when I clone an element and then try to append that element later -- What I thought would happen was essentially a copy/paste -- but it's not working exactly that way--

I have an element .foo

I to make a clone of that element that I can use later

var $clone = $('.foo').clone();

I then do some stuff to the original element

$('.foo').css({'color', 'red'});

Then for whatever reason I need to destroy the original .foo and replace it with the clone:


Then I want to make changes to the new element:


But this doesn't work?

share|improve this question
Define "doesn't work". –  Ilia G Dec 9 '11 at 17:42
after i replace the element with the clone any functions i attempt to perform on the new element don't work -- as in the changes are just not made –  Thomas Dec 9 '11 at 17:44
see my answer below. Your problem has nothing to do with the fact that you are replacing the element with a clone. This demonstrates that: jsfiddle.net/hptmW –  maxedison Dec 9 '11 at 17:46

1 Answer 1

up vote 4 down vote accepted

It doesn't work because your .css() syntax is wrong. When passing an object to that method, as you're doing, you must use colons to separate the property and value, like always in JSON:


To use a comma, remove the curly braces:

share|improve this answer
it was in fact a syntax error, duh... thanks :-D –  Thomas Dec 9 '11 at 18:01

Your Answer


