使用Jquery从DOM中删除元素

时间:2012-11-07 12:29:48

标签: jquery html

这是我的HTML

<div class=" jcarousel-skin-tango">
            <div id="mycarousel" class="jcarousel-container jcarousel-container-horizontal" style="position: relative;
                display: block;">
                <input type="hidden" id="code" name="code" value="0">
                <div class="new4">
                    <div class="jcarousel-clip jcarousel-clip-horizontal" style="position: relative;">
                        <ul style="height: 180px !important; overflow: hidden; position: relative; top: 0px;
                            margin: 0px; padding: 0px; left: 0px; width: 425px;" class="jcarousel-list jcarousel-list-horizontal">
                            **<li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-undefined jcarousel-item-undefined-horizontal jcarousel-item-placeholder jcarousel-item-placeholder-horizontal"
                                style="float: left; list-style: none;"></li>
                            **<li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-NaN jcarousel-item-NaN-horizontal jcarousel-item-placeholder jcarousel-item-placeholder-horizontal"
                                style="float: left; list-style: none;" jcarouselindex="NaN"></li>**
                            <li style="padding-right: 70px; float: left; list-style: none;" class="jcarousel-item jcarousel-item-horizontal jcarousel-item-1 jcarousel-item-1-horizontal"
                                jcarouselindex="1">
                                <div class="new1">
                                    <form name="1">
                                    <input type="hidden" id="0" name="0" value="prodDisplay.php?prodCode=113150">
                                    <div align="center" class="container">
                                        <div id="div01" class="div01">
                                            <a onclick="addToCart('113150','');" title="Add To Cart">
                                                <img src="http://sampanstore.com/images/plus.jpg">
                                            </a>
                                        </div>
                                        <a onclick="addToCart('113150','');" title="Add To Cart">
                                            <img src="http://sampanstore.com/Sood/product_images/small113150.jpg" width="80"
                                                height="90">
                                            <br>
                                        </a>
                                        <div class="box4">
                                            <a title="Quick View" href="javascript:void(0);" class="modal" id="blue" onclick="change_event(0);">
                                                FERRERO ROC... </a>
                                        </div>
                                        <br>
                                        <br style="clear: both; height: 3px;">
                                        <div class="box4">
                                            <div style="float: left; width: 55px; padding-top: 5px;">
                                                <span class="WebRupee" style="font-size: 11pt; text-align: left; margin-left: 10px;">
                                                    Rs. </span><strike style="font-size: 11pt; text-align: left;">545</strike>
                                            </div>
                                            <div class="top-left-corner top-right-corner  box" style="float: right;">
                                                <span class="WebRupee">Rs.</span>539.81</div>
                                        </div>
                                    </div>
                                    </form>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>

我必须使用jquery删除标有**的节点。我试过$(jcarouselindex =“NaN”)。remove();但没用请帮帮我。

3 个答案:

答案 0 :(得分:3)

获取第三个li项,接受所有前任并删除它们:

$('li.jcarousel-item:eq(2)').prevAll().remove()

答案 1 :(得分:1)

试试这个

$([jcarouselindex="NaN"]).remove();

答案 2 :(得分:0)

好吧,你可以试试这个:

$('.jcarousel-item:empty').remove();