I have this code
$(document).ready(function(){
$(\'.selector\').click(function(){
obj = $(this);
obj.replaceWith(\'
Your updated method is the correct one, just needs a tweak like this:
$('.selector').click(function(){
var obj = $(this),
repl = $('whats up man ??! ');
obj.replaceWith(repl);
alert(repl.find('span').attr('class'));
});
You can test it out here. The important change is the repl.find()
to look in the new element instead of the old one.