首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jquery:删除带有2个类名的div

Jquery:删除带有2个类名的div
EN

Stack Overflow用户
提问于 2013-10-16 05:36:14
回答 3查看 783关注 0票数 2

我已经搜索了相当长的一段时间,并使用Jsfiddle进行测试,但我不知道如何选择我需要的。

以下是我的html代码的一部分:

代码语言:javascript
复制
<div id="maincontent">
            <div class="section group">
                <div class="col span_1_of_7">
                    <ul class='kwicks kwicks-vertical'>
                        <li id='panel-1'><a id="keyIssues" href="#">Key Issues</a></li>
                        <li id='panel-2'><a id="pollData" href="#">Poll Data</a></li>
                        <li id='panel-3'><a id="bubbles" href="#">Bubbles</a></li>
                        <li id='panel-4'><a id="dataFrom" href="#">Data Collected From</a></li>
                        <li id='panel-5'><a id="group11" href="#">Group 11</a></li>
                    </ul>
                </div>
                <div class="col span_6_of_7">
                    <section id="infographic">
                        <div id ="infographicContent">
                            <img id="banner" src="images/banner.jpg" alt="Federal Election 2013 Logo" >
                            <div id="chart" style="min-width: 310px; height: 700px; margin: 0 auto"></div>
                            <div id="poll" style="min-width: 310px; height: 700px; margin: 0 auto"></div>
                        </div>
                    </section>  
                </div>
            </div>
        </div>

我希望删除<div class="col span_6_of_7">,然后从文件中追加以下内容:

代码语言:javascript
复制
                    <div class="col span_5_of_7">
                    <section id="infographic">
                        <div id ="infographicContent">
                            <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
                            <script src="js/bubbles.js" ></script>
                            <button>Play</button>
                            <input style="position:inherit;top:4px;" type="range" min="0" max="62" value="0"> 

                        </div>
                    </section>  
                </div>
                <div class="col span_1_of_7">
                    <section id="feed">
                        <div id ="infoFeed">
                          <ul>
                            <li><p><h6>Man Nearly Killed by Train When Car Got Stuck on Tracks</h6>Blames his GPS device for leading him down the wrong road</p></li>
                             <li><p><h6>Two-Year-Old Twins Found Locked in Room Alone</h6>Child Services have taken the girls into protective custody after discovering them naked in an empty room with only one blanket</p></li>
                             <li><p><h6>SNLs 5 Best Skits: NASA Shuts Down, and Bruce Willis Dances</h6>In this week’s episode of Saturday Night Live, hosted by Bruce Willis: plenty of jokes at Congress’s expense, and just a touch of twerking</p></li>
                             <li><p><h6>Man Nearly Killed by Train When Car Got Stuck on Tracks</h6>Blames his GPS device for leading him down the wrong road</p></li>
                            <li><p><h6>Man Nearly Killed by Train When Car Got Stuck on Tracks</h6>Blames his GPS device for leading him down the wrong road</p></li>
                             <li><p><h6>Two-Year-Old Twins Found Locked in Room Alone</h6>Child Services have taken the girls into protective custody after discovering them naked in an empty room with only one blanket</p></li>
                             <li><p><h6>SNLs 5 Best Skits: NASA Shuts Down, and Bruce Willis Dances</h6>In this week’s episode of Saturday Night Live, hosted by Bruce Willis: plenty of jokes at Congress’s expense, and just a touch of twerking</p></li>
                             <li><p><h6>Man Nearly Killed by Train When Car Got Stuck on Tracks</h6>Blames his GPS device for leading him down the wrong road</p></li>
                            <li><p><h6>Man Nearly Killed by Train When Car Got Stuck on Tracks</h6>Blames his GPS device for leading him down the wrong road</p></li>
                             <li><p><h6>Two-Year-Old Twins Found Locked in Room Alone</h6>Child Services have taken the girls into protective custody after discovering them naked in an empty room with only one blanket</p></li>
                             <li><p><h6>SNLs 5 Best Skits: NASA Shuts Down, and Bruce Willis Dances</h6>In this week’s episode of Saturday Night Live, hosted by Bruce Willis: plenty of jokes at Congress’s expense, and just a touch of twerking</p></li>
                             <li><p><h6>Man Nearly Killed by Train When Car Got Stuck on Tracks</h6>Blames his GPS device for leading him down the wrong road</p></li>
                          </ul>
                        </div>
                    </section>  
                </div>

有人能指点我吗,因为我真的很感激?提前谢谢。

bubble.html文件的内容:

代码语言:javascript
复制
    <div class="col span_5_of_7">
    <section id="infographic">
        <div id ="infographicContent">
            <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
            <script src="js/bubbles.js" ></script>
            <button>Play</button>
            <input style="position:inherit;top:4px;" type="range" min="0" max="62" value="0"> 

        </div>
    </section>  
</div>
<div class="col span_1_of_7">
    <section id="feed">
        <div id ="infoFeed">
          <ul>
            <li><p><h6>Man Nearly Killed by Train When Car Got Stuck on Tracks</h6>Blames his GPS device for leading him down the wrong road</p></li>
             <li><p><h6>Two-Year-Old Twins Found Locked in Room Alone</h6>Child Services have taken the girls into protective custody after discovering them naked in an empty room with only one blanket</p></li>
             <li><p><h6>SNLs 5 Best Skits: NASA Shuts Down, and Bruce Willis Dances</h6>In this week’s episode of Saturday Night Live, hosted by Bruce Willis: plenty of jokes at Congress’s expense, and just a touch of twerking</p></li>
             <li><p><h6>Man Nearly Killed by Train When Car Got Stuck on Tracks</h6>Blames his GPS device for leading him down the wrong road</p></li>
            <li><p><h6>Man Nearly Killed by Train When Car Got Stuck on Tracks</h6>Blames his GPS device for leading him down the wrong road</p></li>
             <li><p><h6>Two-Year-Old Twins Found Locked in Room Alone</h6>Child Services have taken the girls into protective custody after discovering them naked in an empty room with only one blanket</p></li>
             <li><p><h6>SNLs 5 Best Skits: NASA Shuts Down, and Bruce Willis Dances</h6>In this week’s episode of Saturday Night Live, hosted by Bruce Willis: plenty of jokes at Congress’s expense, and just a touch of twerking</p></li>
             <li><p><h6>Man Nearly Killed by Train When Car Got Stuck on Tracks</h6>Blames his GPS device for leading him down the wrong road</p></li>
            <li><p><h6>Man Nearly Killed by Train When Car Got Stuck on Tracks</h6>Blames his GPS device for leading him down the wrong road</p></li>
             <li><p><h6>Two-Year-Old Twins Found Locked in Room Alone</h6>Child Services have taken the girls into protective custody after discovering them naked in an empty room with only one blanket</p></li>
             <li><p><h6>SNLs 5 Best Skits: NASA Shuts Down, and Bruce Willis Dances</h6>In this week’s episode of Saturday Night Live, hosted by Bruce Willis: plenty of jokes at Congress’s expense, and just a touch of twerking</p></li>
             <li><p><h6>Man Nearly Killed by Train When Car Got Stuck on Tracks</h6>Blames his GPS device for leading him down the wrong road</p></li>
          </ul>
        </div>
    </section>  
</div>

你好,内特

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-10-16 05:39:52

您可以加载文件内容,然后删除容器。

(在选择器.col.span_6_of_7中使用这两个类)

并在回调中追加加载的代码:

代码语言:javascript
复制
$.get('file.html', function(html){
    $('.col.span_6_of_7').remove();
    $('#maincontent').append($(html));  
});
票数 3
EN

Stack Overflow用户

发布于 2013-10-16 05:39:39

试试这个:

代码语言:javascript
复制
$(".col.span_6_of_7").replaceWith("<div>New Div</div>");

选择器使用两个类选择元素,而replaceWith方法正是这样做的,用一个新元素替换。

http://jsfiddle.net/DRTdR/

票数 1
EN

Stack Overflow用户

发布于 2013-10-16 05:41:03

尝尝这个

代码语言:javascript
复制
$('.col span_6_of_7').replaceWith('.col span_5_of_7')
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19395951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档