Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery: remove first two children?

Tags:

jquery

i have three td's inside of #mainmenu.

<table cellpadding="0" cellspacing="5" id="mainmenu">
    <tbody>
        <tr>
            <td valign="top" class="menu_sub">
                something
            </td>
            <td valign="top" class="menu_sub">
                something
            </td>
            <td valign="top" class="menu_sub">
                something
            </td>
        </tr>
    </tbody>
</table>

I want to remove the first two td's inside of my table, how can i do that?

$('#mainmenu td').remove();
like image 351
matt Avatar asked Mar 08 '11 22:03

matt


People also ask

How to remove child element jQuery?

To remove elements and content, there are mainly two jQuery methods: remove() - Removes the selected element (and its child elements) empty() - Removes the child elements from the selected element.

How to remove dom in jQuery?

remove() method takes elements out of the DOM. Use . remove() when you want to remove the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed.

How remove Li tag in jQuery?

usually <ul> tag contains only <li> tags. If you want to remove all <li> tags then $("#ulelementID"). html(""); will work.

How to remove id value in jQuery?

RemoveAttr('id','none');


2 Answers

Use the less than selector. Here is a jsfiddle

$('#mainmenu td:lt(2)').remove();
like image 133
Josiah Ruddell Avatar answered Oct 11 '22 21:10

Josiah Ruddell


http://api.jquery.com/first-selector/

 $('#mainmenu td:first').remove();
 $('#mainmenu td:first').remove();
like image 27
n00b Avatar answered Oct 11 '22 21:10

n00b