cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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. 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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <body>
  <div class="main" style="text-align:center">
    <h1 style="font-family:Times; text-align:center"> Wikipedia Search Engine</h1>
    <input id="searchbox" class="search" type="text" placeholder="Look On Wiki">

    <a id="random" class="btn btn-primary" href="https://en.wikipedia.org/wiki/Special:Random">Random</a>
  </div>
  <div id="articles">
    <ul class="articles">
    </ul>
  </div>
  <footer style="text-align:center">Inspired by Free Code Camp, coded by <a href="http://freecodecamp/exoran"> Alexandre Robin</a>
</body>
            
          
!
            
              * {
  box-sizing: border-box;
  padding: 20px;
  font-family: Helvetica, Calibri;
  font-size: 16px;
  line-height: 1.5em;
  font-weight: lighter;
}

html {
  margin: 0;
  height: 100%;
  width: 100%;
  background-color: #cfd9df;
  background-repeat: no-repeat;
}

body {
  background-color: transparent;
  height: 100%;
  margin: 0;
  width: 100%;
}

input[type=text] {
  font-size:1em;
  padding: 12px 20px;
  width:70%;
  margin: 8px 0;
  box-sizing: border-box;
  border: 1px solid;
  border-color: #607D8B;
  color: #607D8B;
  text-align: center;
  height: 73px;
  background-image: url('http://www.freeiconspng.com/uploads/search-icon-png-2.png');
  background-size: 30px;
  background-repeat: no-repeat;
  background-position: 3% 50%;
}

input[type=text]:hover {
  cursor: pointer;
  color: #607D8B;
  display: inline;
  text-align: center;
}

.btn {
  background-color: #FFFFFF;
  color: #607D8B;
  display:inline;
  border-color: #607D8B;
  padding: 27px 27px;
  height:73px;
  margin-left: 0;
  border-radius: 0;
  width: 25%;
}

.btn:hover {
  background-color: #607D8B;
  color: #FFFFFF;
  border-color: #ECEFF1;
}

.articles {
  list-style-type: none;
  text-align: justify;
}

.articles:hover {
  text-decoration: none;
}

.main {
  margin: 0 auto;
  width: 50%;
}

#articles {
  margin: 0 auto;
  width: 50%;
}

.result a {
  text-decoration: none;
  color: white;
}

.result {
  margin: 10px 0 10px 0;
  padding: 0 0 0 0;
  background-color: #78909C;
  color: white;
  border-left: 30px solid white;
}

.result:hover {
  border-left: 30px solid #263238;
}

h3 {
  margin: 0 0 0 0;
  padding: 0 0 20px 0;
}

p {
  text-align: left;
  padding: 0 0 0 0;
}
            
          
!
            
              $(function() {
  var results = [];
  var data = "test";
  // Autofocus on the searchbar when reload, do not switch on this feature while coding :) 
  window.onload = function() {
    document.getElementById("searchbox").focus();
  };

  //When I hit enter, I store searchbox's value in "data" then in launch the function 
  $("#searchbox").on("keydown", function search(e) {
    if (e.keyCode == 13) {
      data = $("#searchbox").val().toLowerCase();
      console.log(data);
      lookOnWiki(data);
      return false;
      //console.log(json);
    }
    return true;
  });

  var lookOnWiki = function(data) {

    $.getJSON("https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=" + data + "&prop=info&inprop=url&utf8=&format=json&origin=*", function(json) {
      results = json.query.search;
      console.log(results);
      $(".articles").html("");
      for (var i in results) {
        var title = results[i].title;
        var titleLink = encodeURIComponent(title);
        var link = "http://en.wikipedia.org/wiki/" + titleLink;
        console.log(titleLink);
        var description = results[i].snippet;
        console.log(description);
        $(".articles").append("<div class='result'><a id='link' target='_blank' href=" + link+"><li><h3>" + title + "</h3><p>" + description + "</p></li></a></div>");
      }
      //  $("#link").attr("href",link);
      //  $("li").html(results[i].title);

      console.log(json.query.pages);
    });
  };
});
            
          
!
999px
Loading ..................

Console