I have a table defined like
ButtonSolution 1:
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 ();
});
Copy Solution 2:
http://jsfiddle.net/sfHBn/1/
$(document ).on ("click" , "#first" , function ( ) {
$(this ).closest ("td" ).prev ().html ("" );
});
Copy This will remove all content in previous td
tag.
Solution 3:
You should go up the DOM tree until parent <td>
, then get previous <td>
, find <input>
inside and remove it. You should use on()
with event delegation instead of deprecated live()
:
$(document ).on ("click" , "#first" , function ( ) {
$(this ).closest ("td" ).prev ().find ("input" ).remove ();
});
Copy Note, that instead of document
you may use any other static parent element of #first
.
Solution 4:
I suggest you to use .on()
instead because .live()
is been now removed from the jQuery version 1.9+:
$(document ).on ('click' , "#first" , function ( ){
$(this ).closest ('td' ).prev ().children ().remove ();
});
Copy Click the #first
button and get to the .closest()
<td>
and get the .prev()
element which is a <td>
as well then .remove()
its .children()
.
Solution 5:
Here is the one liner to achieve.
$(this).closest ("td").prev ().remove ();
Copy
Post a Comment for "How To Remove The Content In The Td Tag Using Jquery"