Pen Settings

HTML

CSS

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                <head>
  <title>Wikipedia Viewer</title>
</head>

<body>
  <div id="searchBox" class="">
    <input type="text" id="searchField" class="form-control">
    <div class="row justify-content-center">
      <button id="searchButton" class="btn btn-primary">Search</button>
      <button id="randomPageButton" class="btn btn-primary" onclick="randomPage()">Random Article</button>
    </div>
  </div>

  <ul id="output">
    <ul>

      <footer class="text-center">
        Made by <a href="https://www.freecodecamp.com/radekjohn" target="_blank">Radek John,</a> with use of Wikipedia <a href="https://www.mediawiki.org/wiki/API:Main_page" target="_blank">API</a>.
      </footer>
</body>
              
            
!

CSS

              
                li {
  list-style-type: none;
  margin-bottom: 5%;
}

button {
  margin: 3%;
}

#searchBox {
  margin: 25%;
}

#output {
  margin: auto 10%;
}
              
            
!

JS

              
                $(document).ready(function() {

  // Wait for click  
  $("#searchButton").click(function() {
    // Variable for search term
    var question = "";
    // Varible for API url
    var url = "";
    // Set search term = content of search field
    question = $("#searchField").val();
    // Create API url
    url = "https://en.wikipedia.org/w/api.php?action=opensearch&search=" + question + "&format=json&callback=?";

    // Get API -- I had to use coding360 tutorial for this part :-(
    $.ajax({

      url: url,
      async: false,
      dataType: "json",
      type: "GET",
      success: function(data) {
          // Remove old results
          $("#output").html("");
          // Go through data
          for (var i = data[1].length - 1; i >= 0; i--) {
            // Ad item to the list of results  
            $("#output").prepend("<li>" +
              // Make h6 header inside link 
              "<a href=" + data[3][i] + ">" +
              "<h6>" + data[1][i] + "</h6>" +
              "</a>" +
              // Ad text
              data[2][i]
              // Close list item
              +
              "</li>");

          }
          $("#searchBox").css("margin-top", "0%");
          $("#searchBox").css("margin-bottom", "0%");

        }
        // Belongs to  $.ajax( ...    
    });
    // Belongs to  $("#searchButton")...  
  });

  // Belongs to  $(document).ready ... 
});

// Go to random Wikipedia page
function randomPage() {
  window.open("https://en.wikipedia.org/wiki/Special:Random");
}
              
            
!
999px

Console