user2818430
user2818430

Reputation: 6029

Remove all li from ul inside a div

I need to remove all items from a list that is inside a div using jQuery

The problem is that the ul has no class or id but the div has an id.

<div id="myDiv">
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
    </ul>
</div>

Upvotes: 1

Views: 5157

Answers (2)

use .empty()

$('#myDiv > ul').empty();

Upvotes: 3

Denys S&#233;guret
Denys S&#233;guret

Reputation: 382150

You seem to want

$('#myDiv ul li').remove();

Upvotes: 4

Related Questions