删除p标签,如果它包含某个类

时间:2012-06-11 18:56:31

标签: jquery

 <div id="info-leftside">
                <div class="label-container" id="name-label"><p class="info-field-label">name</p><p class="error">error</p></div>
                <input type="text" name="name" id="name" class="field"/>
                <div class="label-container" id="email-label"><p class="info-field-label">email</p></div>
                <input type="text" name="email" id="email" class="field"/>
                <div class="label-container" id="phone-label"><p class="info-field-label">phone</p><p class="error">error</p></div>
                <input type="text" name="phone" id="phone" class="field"/>
                <div class="label-container" id="address1-label"><p class="info-field-label">address (line 1)</p></div>
                <input type="text" name="address1" id="address1" class="field"/>
                <div class="label-container" id="address2-label"><p class="info-field-label">address (line 2)</p></div>
                <input type="text" name="address2" id="address2" class="field"/>
                  <div class="label-container" id="city-label"><p class="info-field-label">city</p></div>
                <input type="text" name="city" id="city" class="field"/>

</div>

删除包含类“错误”的p标记的最有效方法是什么?我应该在类标签容器上使用hasClass吗?但那我如何才能删除?

1 个答案:

答案 0 :(得分:6)

$('.error').remove()怎么样?

如果您对其他元素使用相同的类,则提供

或更具体的$('p.error').remove()