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.

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

            
              <div id="container">
    <p id="main_header">Wikipedia Search</p>
    <input id="search_box" type="text"><input id="search_button" type="submit" value="search">
    <div class="wrapper">
        <br />
        <a id="random" href="https://en.wikipedia.org/wiki/Special:Random" target="_blank">I'm Feeling Adventurous</a>
        <ul id="search_results"></ul>
    </div>
    <a id="portfolio" href="http://www.danielstrong.io" target="_blank">by daniel strong</a>
</div>
            
          
!
            
              * {
    box-sizing: border-box;
}

.clearfix {
    content: "";
    display: table;
    clear: both;
}

body {
    background-color: #333;
    font-family: 'Raleway', sans-serif;
    color: #ccc;
}

hr {
    width: 92%;
    height: 1px;
    border: none;
    background-color: #FFBB00;
    margin: 40px auto;
}

hr:last-of-type {
    margin-bottom: 10px;
}

a {
    text-decoration: none;
}

#main_header {
    font-size: 2.5em;
    margin: 25px auto 50px auto;
}

#container {
    width: 700px;
    height: 450px;
    text-align: center;
    padding: 50px;
    margin: 0 auto;
}

.wrapper {
    text-align: center;
}

#search_box {
    width: 300px;
    height: 35px;
    background-color: #dedede;
    color: #333;
    letter-spacing: .05em;
    border-style: none;
    border-left: 4px solid #FFBB00;
    padding: 0 10px;
}

#search_box:focus {
    outline-color: #FFBB00;
}

#search_button {
    height: 35px;
    color: #fff;
    background-color: #666;
    border-style: none;
    border-right: 4px solid #FFBB00;
    border-left: 4px solid #FFBB00;
    padding: 0 20px;
}

#search_button:hover {
    background-color: #2B8BCF;
}

#search_button:focus {
    outline: none;
}

#random {
    display: inline-block;
    color: #ccc;
    text-decoration: none;
    padding: 15px;
}

#random:hover {
    color: #FFBB00;
}

#search_results {
    width: 100%;
    text-align: left;
    list-style: none;
    padding: 0;
    margin: 0 auto;
}

.title {
    color: #FFBB00;
    font-size: 1.35em;
    margin: 0 0 5px 0;
}

.link {
    width: 100%;
    color: #dedede;
    font-size: .9em;
    cursor: default;
    padding: 25px;
    margin: 10px auto;
}

.link:hover {
    background-color: #404040;
    box-shadow: -4px 0 0 #2B8BCF;
}

#portfolio {
    visibility: hidden;
    float: left;
    display: inline-block;
    color: #999;
    padding: 25px;
    margin-bottom: 100px;
}

#portfolio:hover {
    color: #dedede;
}
            
          
!
            
              // Get value from search input and retrieve from Wikipedia API
function search() {
    input = document.getElementById('search_box').value;
    $.getJSON('http://en.wikipedia.org/w/api.php?format=json&formatversion=2&action=query&generator=search&gsrnamespace=0&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch=' + input + '&callback=?', searchReturn)
}

// Append search results to unordered list
function searchReturn(json) {
    results = json;
    ul = document.getElementById('search_results');
    html = '<hr>';
    
    // Append each search result with styling to list
    for (i = 0; i < results.query.pages.length; i++) {
        html += '<a href="http://en.wikipedia.org/?curid=' + results.query.pages[i].pageid + '" target="_blank"><li class="link"><p class="title">' + results.query.pages[i].title + '</p>' + results.query.pages[i].extract + '</li></a>';
    }

    html += '<hr>';
    ul.innerHTML = html;
    // Make footer link to my website visible
    document.getElementById('portfolio').style.visibility = 'visible';
}

// Event listeners for search button and pressing 'ENTER' to submit search
document.getElementById('search_button').addEventListener('click', search);
document.getElementById('search_box').addEventListener('keypress', function(event) {
    var key = event.which;
    if (key === 13) {
        search();
    }
});
            
          
!
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