I have a table defined like
<table>
<tr>
<td>
<input type='text' />
</td>
<td>
<button id ='first'>Button</button>
</td>
<td>
<input type='text' />
</td>
</tr>
$("#first").live('click',function(){
$(this).prev().remove();
$(this).remove();
});
How can i remove the previous element in the td
. But i don't want to remove the td
If you want to remove the complete contents of that previous TD (rather than a specific INPUT element), this will work:
$(document).on("click", "#first", function() {
$(this).closest("td").prev().empty();
});
http://jsfiddle.net/sfHBn/1/
$(document).on("click", "#first", function() {
$(this).closest("td").prev().html("");
});
This will remove all content in previous td
tag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With