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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

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

Console