Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <div class="container" id="container-div">
      <h1>Wikipedia Viewer</h1>
      <div class="row">
            <div class="col s3"></div>
            <form class="input-field col s6" method="POST" id="search-form">
                  <input id="search-box" placeholder="Search me" type="text">
                  <input type="submit" class="hidden" />
            <div class="col s3"></div>
      <div class='row'>
            <div class="chip" id="search-term"></div>
            <a href="" target="_blank" id="random-search-btn" class="waves-effect waves-light btn">Random</a>

      <div id="results-container"></div>



                .hidden {
      display: none;
.container {
      text-align: center;

#random-search-btn {
      margin-bottom: 20px;


                // API url string to add
var apiUrl = "";
var finalUrl = "";
// var returnJson = {}; Do we need to decalre the global obj
var searchInput = "";

var searchArr = [];

// Add event listener to capture form input
var form = document.getElementById("search-form");
if (form.attachEvent) {
      form.attachEvent("submit", captureForm);
} else {
      form.addEventListener("submit", captureForm)

// var z = document.getElementById('random-search-btn');  TO DELETE IF BUTTON WORKS WITHOUT
// z.addEventListener('click', randomSearch);

// function to reset the variables used in the search() function 
function resetVariables() {
      finalUrl = undefined;
      searchInput = undefined;
      searchArr = undefined;

// deleteResults() fucntion to remove DOM elements from last search
function deleteResults() {
      var myNode = document.getElementById('results-container');
      while (myNode.firstChild) {

function captureForm(e) {
      // returnJson = {}; is this the best way to clear the obj each new search
      if (e.preventDefault) e.preventDefault();
      // log form input into searchInput variable
      searchInput = document.getElementById("search-box").value;
      // Have to return false to prevent default behaviour
      if (searchInput !== "") {
            finalUrl = apiUrl + searchInput + "&format=json";
      } else {
            console.log("user did not search anything");
            // MUST ADD -- UI interaction to let the user know they need to search something


// Create the XHR object.
function getSearchData() {
      var request = new XMLHttpRequest();'GET', finalUrl, true);
      request.onload = function() {
            console.log("function has fired");
            if (request.status >= 200 && request.status < 400) {
                  // Success!
                  searchArr = JSON.parse(request.responseText);
            } else {
                  // We reached our target server, but it returned an error
      request.onerror = function() {
            // There was a connection error of some sort

function updatePage() {
      // Add search term to Materialze chip compontent
      document.getElementById("search-term").innerHTML = searchArr[0];
      // code loops through the array from the JSON API response to dynamically build the HTML elements containing the search results and adds them to page
      for (var i = 0; i < searchArr[1].length; i++) {
            var div = document.createElement('div');
            div.className += 'col s10';
            var a = document.createElement('a');
            a.href = searchArr[3][i];
            a.setAttribute("target", "_blank");
            var innerDiv = document.createElement('div');
            innerDiv.className += 'card-panel teal white-text';
            var contentTitle = document.createElement('h5');
            contentTitle.innerHTML = searchArr[1][i];
            var content = document.createElement('p');
            content.innerHTML = searchArr[2][i];
            // completed Div to page