tags:

views:

84

answers:

2

Say for example I have a body with the class "test" and I want to take that class and add it to another div, how can I do this with jQuery?

Thanks

Edit: Something like this?

 $("body.test").clone().attr("class").prependTo("div");
A: 

Not sure what you want, but perhaps you mean clone()?

kgiannakakis
I do, I just dont know how to execute correctly... Something tells me I have to use attr?
Bruno
+1  A: 

$('element').hasClass("test", function() { $('element2').addClass("test"); } );

should do it - syntactically untested, but it's roughly what I'd do.

Terry_Brown
Syntactically should be something like:if ( $('element').hasClass("test") ){ $('element2').addClass('test');}seems to be the method structure - can never remember syntax!
Terry_Brown