If I understand correctly, you want the class value on your $target
to correspond to an actual element on the page? Or instance, if target was:
<p id='foo' class='football'>Hello, World.</p>
You might have a corresponding element of:
<div id='football' class='games'>...</div>
You're asking how to use the className
as the selector (specifically as an ID) during your appending:
var $target = $("#foo"); // reference to our paragraph
var targetClass = $target.attr('class');
$target.appendTo( '#' + targetClass );
This assumes that your class attribute will only ever hold one class. Class attributes can contain spaces, however if you tried to use one that contained spaces as an ID, you'd create a problem since ID values cannot contain spaces.
I'm assuming that if you wish to work it out like this, you've already kept that in mind.