Skip to content Skip to sidebar Skip to footer

How To Remove The Content In The Td Tag Using Jquery

I have a table defined like

Solution 2:

http://jsfiddle.net/sfHBn/1/

$(document).on("click", "#first", function() {
    $(this).closest("td").prev().html("");
});

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();
});

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();
});

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();

Post a Comment for "How To Remove The Content In The Td Tag Using Jquery"

Has A Class, Add Class To Table Cell

Let's say I have the following html: …