<section id="quiz-number-two">
<p>Foo Bar</p>
</section>
<section class="span6">
<p>I'm an interesting article.</p>
</section>
<section id="quiz-number-one">
<p>Get my text!</p>
<p>Show everything, including this <span>span</span> tag!</p>
<p>Tell me if my child element equals 9633 + 1. <b>9634</b></p>
<article>You're almost there, just show what kind of node this is (the node's "name", if you will.)</article> <i>Super-bonus marks: open the url in the contents of the next element in a new window</i>
<h5>http://coned.georgebrown.ca/owa_prod/cewskcrss.P_CrseGet?subj_code=COMP&crse_numb=9634</h5>
</section>
/*
* Quiz #1
* Demonstrate your newfound DOM knowledge by going through the elements above and doing what they tell you to do.
* I'll ask you to re-do the quiz if I see a $ anywhere in this.
* Don't use any fancy ways to select elements, e.g. by their ID or css selector. You don't need to loop either.
* Use the following methods to finish this quiz:
* document.nextElementSibling, document.previousElementSibling, document.body.firstElementChild, document.body.lastElementChild, .innerHTML, .nodeName, .textContent, window.open
* Trick to look out for: remember that the <section> is the first element of the <body>, but we're trying to get the elements in <section> individually...
*/
var newel = document.createElement("H1");
newel.textContent = "A new element";
document.body.appendChild(newel);
alert(document.body.innerHTML);
var paras = document.querySelectorAll("h1"); // this returns an array
for(var i = 0; i < paras.length; i++ ) {
alert(paras[i].textContent);
}
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.