// Advanced selectors
// And Modifying selections
//
// This exercise is intended to give you
// a feel for using modifiers on selections
// as well as the context selector
//
// Follow the instructions below to select each
// element and apply a style change to them
//
// .css("border", "1px solid red");
//
// 1.
// Get the unordered list (ul) that is NOT
// in #container
//$("ul").not("#container").css("border", "1px solid red");
// 2.
// Get the unordered list that has a "span"
// inside it
$("ul").has("span").find("span").css("border", "5px solid red");
// 3.
// Get the unordered list that is in #container
// Do so with the "context selector"
$("ul", "#container");
// 4a.
// Select all inputs and store them in a variable
var inputArray = $("input");
console.log(inputArray.length);
// 4b.
// Within the input results, filter it for all text inputs
var textInputArray = inputArray.filter("[type=\"text\"]");
// 4c.
// Add input types of "date" to your previous selection
console.log("Hello : " , textInputArray.add("input[type=\"date\"]"));
// 5a.
// Get all fieldsets (store this for use later)
var fieldsetArray = $("fieldset");
console.log(fieldsetArray);
// 5b.
// Find all h2 elements inside the fieldset result from 5a
var h2Array = fieldsetArray.find("h2");
console.log(h2Array);
// 5c.
// Write the above as a "context selection" instead
var fieldsetArrayUsingContext = $("h2", "fieldset");
console.log(fieldsetArrayUsingContext);
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.