css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div container-fluid>
  <section id="Top">
    <div class="row">
      <div class="col-xs-12  heading ">
        <h1 id="headingTxt">Wiki Search Tool</h1>
      </div>
    </div>
    <div class="row" >
      <div class="col-xs-8  input ">
        <input type="text" id = "myInput" placeholder="Enter search criteria here" >
      </div>
    </div>
    <div class="col-xs-8  random">
      <h1 id="random">Click<a href=" https://en.wikipedia.org/wiki/Special:Random" target = "_blank"> Here </a>For Random Wiki Item </h 1>
    </div>
    <div class = "test"><h1> </h1>
</div>
            
          
!
            
              body {
  
  background-color:grey;
}


.heading {
  text-align: center;
}

.input {
  text-align: center;
}

.random {
  text-align: center;
}

.test {
  text-align: left;
}

            
          
!
            
              var wikiurl = ""; // to hold url for api call
var infoFromWiki = []; // to hold info returned from wiki

function getText() {
  txt = $('#myInput').val();
  return txt;
}

// write data to Html
$(document).ready(function() {
  var text_value = ""; // to hold input txt 

  $('#myInput').change(function() {
    text_value = getText(); // get txt from input

    // create  (suggested)url for wiki API 
    wikiUrl = "https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=" + text_value + "&prop=revisions&rvprop=content&format=json&callback=?";

    console.log("wikiUrl = " + wikiUrl);

    //request info using API and Url
    $.getJSON(wikiUrl, function(json) {
      infoFromWiki = json.query.search;

      // this line for testing only 
      // $(".test").html(JSON.stringify(infoFromWiki));
      // var tmp = "";
      var mytable = "<table cellpadding=\"0\" cellspacing=\"0\"><tbody><tr>";
      var titleStr = ""; // to hold title info for 
      var titleUrl = ""; // to hold url for each block
      //console.log("start of for 1"); // test print to console
      //console.log("infoFromWiki.length = " + infoFromWiki.length); // test print to console
      for (i = 0; i < infoFromWiki.length; i++) {
        // console.log("start of for 2"); // test print to console
        // console.log("infoFromWiki[i].title = " + infoFromWiki[i].title); // test print to console
        titleStr = infoFromWiki[i].title; // get page title
        titleUrl = "https://en.wikipedia.org/wiki/" + titleStr // construct title url
        titleUrl = titleUrl.replace(/ /g, '%20'); // sort spaces in url
        console.log("titleurl = " + titleUrl); // test url print
        mytable += "<a style= \x22display:block\x22 href =" + titleUrl + " target=\x22_blank\x22><p>" + infoFromWiki[i].title + "</p><p>" + infoFromWiki[i].snippet + "</p>" + "<p></a>" + "<p>" + "=======================================================================================================" + "</p>";

      };

      //mytable += "<div></tr></tbody></table></div>";
      $(".test").html(mytable);

    });

  });
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console