// 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
var sort = function () {
var $newUl = $(".new");
var $grapeEl = $("<li>Grapes</li>");
$grapeEl.addClass("fresh glyph-grapes");
$grapeEl.css({color:"white", backgroundColor:"purple"});
$grapeEl.appendTo($newUl);
// 2
// Remove any "spoiled" (based on class)
// list items from the page entirely
$(".spoiled").fadeOut( function() {$(this).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)"
$(".glyph-cherry").appendTo($newUl).append(" (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"
var $appleEl = $(".glyph-apple").clone().prependTo($newUl);
$appleEl.attr("data-type", "green").removeClass("mushy").addClass("fresh");
};
$(document).ready(function() {
$("#sorter").one('click', function() {
sort();
});
});
var clickHandler = function(e) {
$(this).hide();
}
// 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
// 6 (Bonus)
// Animate your manipulations
// Update your sort() function so that:
// For any...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.