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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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="container text-center">
  <div class'center row col-xs-4'>
    <h1>Wikipedia Search</h1>
    <input type="textbox" id="text" placeholder="Search Wikipedia">
    <input type="button" id="button" class="btn btn-primary" value="Search">
      <div class="random">
        <a href="http://en.wikipedia.org/wiki/Special:Random">Click Here For a Random Page</a>
      </div>  
  </div>
  <div id="workspace" class="row">

  </div>
  <div class="footer">Created by &copy Randy Goldsmith using Wikipedia API</div>
</div>

              
            
!

CSS

              
                body {
 background: #2B745E;
}


.center {
  margin: 100px;
  height: 50px;
  text-align: center;
}

.extract {
  width: 100%;
  padding: 10px;
  text-align: center;
  height: auto;
  font-size: 15px;
  color: black;
}

h1 {
  color: #070b7a;
  margin-bottom: 30px;
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 2.5em;
}

.title {
  margin: auto;
  width: 50%;
  text-align: center;
}

#format {
  margin: 20px auto;
  width: 90%;
  background: #305073;
  -webkit-border-radius: 25px;
  -moz-border-radius: 25px;
  border-radius: 25px;
  border: 2px solid black;
  padding: 0.9em;
}

#text{
  padding: 5px 12px;
}


#button{
  margin-left: 10px;
  width: 100px;
}

.random{
  margin-top: 50px;
}

.break{
  width: 33%;
  margin-top: 10px;
  }
.random a:hover{
  color: #0f1616 ;
}
.random a{
  color: #7f0e37;
}

.title a {
  color: white;
}

.title a:hover{
  color: black;
}

@media screen and (min-width: 720px){
  #format {
    width: 75%;
  }
}
              
            
!

JS

              
                $(document).ready(function(){

$("#text").keypress(function(event) {
  if (event.which === 13) {
    doSearch($(this).val());
    clearSearchBox();
  }
})

$("#button").click(function(e) {
  e.preventDefault();
  doSearch($('#text').val());
  clearSearchBox();
})

function clearSearchBox() {
  $('#text').val('');
}


function doSearch(enteredSearch) {
  $('#workspace').html('');
 
  var api = 'https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&generator=search&exsentences=1&exlimit=10&exintro=1&explaintext=1&gsrsearch=' + enteredSearch + '&gsrnamespace=0&gsrwhat=text&callback=?'

  $.ajax({
    url: api,
    dataType: 'json',
    type: 'GET',
    contentType: 'application/json',
    success: function(data) {
       //console.log(JSON.stringify(data))
      var keys = Object.keys(data.query.pages);
//var linkID = "http://en.wikipedia.org/?curid=" + key + '"';
//var curID = data.query.pages[keys];
//console.log(keys);

    
      // console.log(data.query.pages[keys[0]])
      keys.forEach(function(key) {
        var linkID = "http://en.wikipedia.org/?curid=" + key + '"';
        var entry = data.query.pages[key];
        $('#workspace').append('<div id="format">' + '<h3 class="title">' + '<a href=' + linkID + '>' + entry.title + '</a>' + '</h3>' + '<hr class="break">' + '<p class="extract">' + entry.extract + '</p>' + '</div>');
       // console.log(key);
      })
    }
  });
 }
});
              
            
!
999px

Console