Nate Uni
Nate Uni

Reputation: 943

Jquery: remove div with 2 class names

I have been searching for quite some time and using Jsfiddle to test, but I cannot figure out how to select what I need.

Here is part of my html code:

<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>

I want to remove the <div class="col span_6_of_7"> and then append the following from a file:

                    <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>

Can someone enlighten me please, as it would really be appreciated? Thanks in advance.

Contents of the bubble.html file:

    <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>

Regards, Nate

Upvotes: 2

Views: 792

Answers (3)

gherkins
gherkins

Reputation: 14973

You could load the file contents, then remove the container
(by using both classes in the selector .col.span_6_of_7)
and append the loaded code in the callback:

$.get('file.html', function(html){
    $('.col.span_6_of_7').remove();
    $('#maincontent').append($(html));  
});

Upvotes: 3

Dennis Flagg
Dennis Flagg

Reputation: 664

Try this

$('.col span_6_of_7').replaceWith('.col span_5_of_7')

Upvotes: -1

Hanlet Esca&#241;o
Hanlet Esca&#241;o

Reputation: 17370

Try this:

$(".col.span_6_of_7").replaceWith("<div>New Div</div>");

That selector selects the element with the two classes, and the replaceWith method does exactly that, replaces with a new Element.

http://jsfiddle.net/DRTdR/

Upvotes: 1

Related Questions