1

我正在尝试删除所有存在<div>sflag. 正确的方法是什么?不知何故,我所做的一切都行不通。editdeletediv container

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Side bar poll thingy</title>
<script type="text/javascript" src="http://localhost/site/scripts/jQueryCore.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $(".add").click(function() {
    $("#container").remove('.flag, .edit, .delete');
    $(this).parent("div").after("<div class='flag'>I'm the new one.</div>");

    });
});
</script>
</head>
<body>

<div id="container">

    <div class="h1" data-id="1">Teachers <span class="add" data-id="US01">Add New</span></div>
    <div class="flag">Flag</div>
    <div class="edit">Edit</div>
    <div class="h2" data-id="2">Who is your favorite Math teacher? <span class="add" data-id="US02">Add New</span></div>
    <div class="flag">Flag</div>
    <div class="edit">Edit</div>
        <br>
    <div class="h1" data-id="8">Restaurants <span class="add" data-id="US10">Add New</span></div>
    <div class="flag">Flag</div>
    <div class="edit">Edit</div>
    <div class="h2" data-id="9">Which is your favourtie restaurant in town? <span class="add" data-id="US20">Add New</span></div>
    <div class="flag">Flag</div>
    <div class="edit">Edit</div>

</div>

</body>
</html>
4

3 回答 3

6
$("#container").find('.flag, .edit, .delete').remove();
于 2013-09-06T07:21:49.897 回答
0

您的问题的可能解决方案是这样

$(document).ready(function() {
    $(".add").click(function() {
        $("#container .flag").add("#container .edit").add("#container .delete").remove();
        $(this).parent("div").after("<div class='flag'>I'm the new one.</div>");
    });
});

http://jsfiddle.net/3qLQz/1/

于 2013-09-06T07:26:16.683 回答
0

你也可以这样做:

$("#container .flag, #container .edit, #container .delete")
.remove();
于 2013-09-06T07:24:41.200 回答