JSFiddle - React, Tailwind, and code Playground

by Jennifer Piccione

HTML

<div id="container">
     <h1>Hello, DOM!</h1>

    <button id="sorter">Sort fruit</button>
    
    <p>This is some old fruit:</p>
    
    <ul class="old">
        <li class="glyph-apple mushy" data-type="red">Apples</li>
        <li class="glyph-pear spoiled">Pears</li>
        <li class="glyph-cherry">Cherries</li>
    </ul>
    
    <p>This is some fresh fruit:</p>
    
    <ul class="new"></ul>
    
</div>

CSS

.spoiled{
    background-color:#ccc;
}

.fresh{
    border:1px dotted green;
}


ul li,
.glyph{
    padding:3px 0 3px 25px;
   background-repeat:no-repeat;
    background-size:20px 20px;
    background-position:middle left;
}

.glyph-cherry{
    background-image:url('http://cdn.flaticon.com/png/64/2146.png');
    
}
.glyph-apple{
     background-image: url('http://cdn.flaticon.com/png/64/18251.png');
    
}

.glyph-pear{
    background-image:url('http://cdn.flaticon.com/png/64/2158.png');
}

.glyph-grapes{
    background-image:url('http://cdn.flaticon.com/png/64/18353.png');
}

JavaScript

// Content manipulation
//
// Use jQuery to complete the following
// You will be adding, moving, and manipulating content
// 
// Warnings:
// a. Be sure to write your code so it runs on document ready only
// b. Take care not to REMOVE classes or attributes unless 
// told to do so in each task below

// 1
//     Create a new "Grapes" list item in the "new" list
//     Give it two additional classes: "fresh" and "glyph-grapes"
//     Then style it with white text and a purple background

$(function() {
    $(".new").append("<li>Grapes</li>");
    $(".new li").addClass("fresh");
    $(".new li").addClass("glyph-grapes");
    $(".new li.glyph-grapes").css({"background-color": "purple", "color": "white"});
});   

// 2
//     Remove any "spoiled" (based on class)
//     list items from the page entirely

$(function() {
    $("li.spoiled").remove(); 
});
 
// 3
//     Move "Cherries" into the "new" list as the last item
//     Add text to the list item, "(10)" to indicate you have ten cherries. 
//    Resulting text: "Cherries (10)"

$(function() {
    $("ul.new").append($("li.glyph-cherry"));
    $("ul.new li.glyph-cherry").text($("ul.new li.glyph-cherry").text() + " (10)");
});

// 4
//     Copy "Apples" into the "new" list as the first item
//     Set it's data-type attribute value from "red" to "green" 
//     Remove the class "mushy" and give it a class of "fresh"

$(function() {
    $("ul.new").prepend($("li.glyph-apple"));
    $("ul.new li.glyph-apple").attr("data-type", "green");
    $("ul.new li.glyph-apple").removeClass("mushy");
    $("ul.new li.glyph-apple").addClass("fresh");
});

// 5
//    Bring it together
//    Write a function, "sort()" that will perform all
//    the manipulations you wrote above
//    To test, uncomment the sort() invokation line
//    then press the sort button
 
    
$("#sorter").one('click', function() {
   //sort(); //<!-- uncomment me when you have written sort()
});



// 6 (Bonus)
//    Animate your manipulations
//   ...