<div id="container">
<h1>Find the flag elements.</h1>
<p>There are three flags ("FLAG") in the content below. When a user clicks on a flag, move it into the #bucket element.</p>
<div class="main">
<ul>
<li>One</li>
<li>FLAG #1</li>
<li>Three</li>
</ul>
<div id="articles">
<article class="new">
<h3>Article 1</h3>
<p>This is <a href="#">some</a> body content</p>
<p>This is some body content <a class="flag" href="#">FLAG #2</a>
</p>
</article>
<article class="new">
<h3>Article 2</h3>
<p>This is some body content</p>
</article>
<article>
<h3>Article 3</h3>
<p>This is some body content</p>
</article>
<div class="footer">
<div>
<div>
<div></div>
<div>
<div>FLAG #3</div>
<div></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="bucket">
<h2>Dropped Flags:</h2>
<!-- Where are my flags? -->
</div>
</div>
//Using Factory Pattern
// Make the following code work:
var bucket = {
// Fill out this function
var bucketId = "",
var registerClickListener = function (e) {
var dropElem = document.getElementById(bucketId);
dropElem.appendChild(e.target);
},
var moveOnClick = function (locator) {
console.log(locator);
var flagElem = document.querySelector(locator);
flagElem.addEventListener('click',
registerClickListener,
true // use bubble method
);
};
};
var Bucket = function (bucket_id) {
var bucket = Object.create(bucket);
bucket.bucketId = bucket_id;
return bucket;
};
// To make this code work:
var bucket = Bucket("bucket");
bucket.moveOnClick(".main li:nth-child(2)");
bucket.moveOnClick("#articles .flag");
bucket.moveOnClick(".footer div div div div");
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.