This was created by stackoverflow 🙂
<table border="2" class="table">
<tr> <td class="clicked">aaa </td> <td class="clicked">bbb </td> </tr>
<tr> <td class="clicked">ccc </td> <td class="clicked">ddd </td> </tr>
</table>
<table border="2" class="tablehide">
<tr> <td> 111</td> </tr>
<tr> <td> 222</td> </tr>
</table>
$(".clicked").live('blur', function() {
$(".clicked").find('.tablehide').remove();
});
$(".clicked").live('click', function() {
$(".clicked").find('div:first').show();
$(this).wrapInner('<div class="hide">');
$(this).find('div:first').hide()
$(this).prepend($('.tablehide'));
$('.tablehide td').show();
});
LIVE EXAMPLE: http://jsfiddle.net/5neff/7/
how can i modify this – i would like that if i click outside table then table return to previous state – aaa bbb ccc ddd
Instead of
liveusedelegateand attach a click handler ondocumentto reset the state as show in the below code. In your code you were always wrapping thetdcontent with<div class="hide">even if its already wrapped. I have also taken care of that in my code.Working demo