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

              
                <div class="row teal">
  <div class="col s8 offset-s2 center-align page-title">
    <h3>WIKIPEDIA SEARCH</h3>
  </div>
</div>

<div class="row">
  <form class="search">
    <div class="col s8 offset-s2">
      <input class="search-input" type="text" placeholder="Enter your search">
    </div>
    <div class="col s2">
      <input class="btn" type="submit" value="Go">
    </div>
  </form>
</div>

<div class="row">
  <div class="col s12 center-align">
    <a class="btn" href="https://en.wikipedia.org/wiki/Special:Random">Or get a random article</a>
  </div>
</div>

<div class="row">
  <div class="col s10 offset-s1">
    <div class="search-results">
    </div>
  </div>
</div>
              
            
!

CSS

              
                a {
  color: black;
}

.page-title {
  color: #fff;
}
              
            
!

JS

              
                $(document).ready(function() {

  var language = 'en',
    searchInput = $('.search-input'),
    searchForm = $('.search'),
    resultsDiv = $('.search-results'),
    searchTerms = '',
    searchResults = [];
    
  // On submit event, call the search function with input contents
  searchForm.submit(function(event) {
    event.preventDefault();
    searchTerms = searchInput.val().toLowerCase();
    search(searchTerms);
  });

  // Send api request
  function search(terms) {
    $.ajax({
      dataType: 'jsonp',
      url: 'https://' + language + '.wikipedia.org/w/api.php?action=opensearch&format=json&search=' + terms,
      success: function(data) {

        // clear results & html
        searchResults = [];
        resultsDiv.html('');

        // clean up api reply
        for (var i = 0; i <= data[1].length - 1; i++) {
          var d = {};
          d.title = data[1][i];
          d.snip = data[2][i];
          d.link = data[3][i];
          searchResults.push(d);
        }
        
        // render
        showResults();
        
      },
      error: function() {
        console.log('api request fail');
      }
    });
  };

  function showResults() {
    // show resultsDiv on first search
    if (resultsDiv.hasClass('hide')) {
      resultsDiv.toggleClass('hide');
    }
    // populate resultsDiv
    for (var i = 0; i < searchResults.length - 1; i++) {
      resultsDiv.append('<ul><a href="' +
        searchResults[i].link +
        '"><li class="card-panel hoverable teal lighten-3"><h4>' +
        searchResults[i].title +
        '</h4><p>' +
        searchResults[i].snip + '</p></li></a>');
    }
    resultsDiv.append('</ul>');
  };
});
              
            
!
999px

Console