Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                
<body>
    <div class="container">
        <div class="mainBox">

            <a href="https://en.wikipedia.org/wiki/Special:Random" target="#blank" id="randomWiki">Click here for a random article</a>


            <div id="searchBox">
                <!-- See iFrame comments below -->
                <form target="iFrame">

                    <button aria-label="searchIcon" id="searchIcon" type="button">
                        <i class="fas fa-search"></i>
                    </button>
                    <button aria-label="clearSearch" id="clearSearch" type="button">
                        <i class="far fa-times-circle"></i>
                    </button>
                </form>
            </div>
            <div class="text">Click icon to search</div>
            <div id="searchResults"></div>
        </div>

        <!-- <span>
            <input type="search" id="input">
        </span> -->

    </div>
    <!-- added this iframe to give the form a target to stay on same page withour reloading -->
    <iframe name="iFrame" style="display:none;"></iframe>
              
            
!

CSS

              
                body {
  font-family: "Lucida Grande", "Lucida Sans Unicode", Tahoma, Sans-Serif;
  background: #092b40;
  color: white;
}

a {
  text-decoration: white;
  color: white;
  text-align: center;
}
a:hover {
  text-decoration: none;
  color: white;
}

button {
  cursor: pointer;
}
.fa-search {
  opacity: 1;
}
.mainBox {
  margin-top: 30vh !important;
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#searchIcon {
  border: none;
  background: none;
  color: #d96f32;
  font-size: 1.5em;
}

#clearSearch {
  border: none;
  background: none;
  color: #d96f32;
  font-size: 1.5em;
  display: none;
}

#input {
  background: #092b40;
  padding: 0 15px 0 15px;
  border: solid 4px #d96f32;
  color: white;
  width: 250px;
  height: 40px;
  border-radius: 20px;
  animation: appear ease-out 1s;
}

@keyframes appear {
  0% {
    width: 0px;
    background: #d96f32;
  }

  100% {
    width: 250px;
    background: #092b40;
  }
}
#input::after {
}

.container {
  display: flex;
}

#randomWiki {
  /* display: flex;
  text-align: center; */
}



.result {
  padding: 10px 40px ;
  margin: 20px;
  background: #197bb8;
  box-shadow: 5px 5px 8px rgb(54, 54, 54);
}

.result:hover {
  border-left: #d96f32 solid 5px;
  padding-left: 35px;
}

.title {
  color: #c3c9cc;
  text-align: left;
  font-weight: bolder;
  border-bottom: 1px solid #d96f32;
}

.snippet {
  text-align: left;
}

/* #searchResults {
  display: block;
} */

              
            
!

JS

              
                var results = [];
$("document").ready(function() {
  console.log("doc ready!");

  $("#searchIcon").click(function() {
    console.log("icon clicked");
    $("form").prepend('<span><input type="search" id="input" ></span>');
    $("#searchIcon").css({ display: "none" });
    $("#clearSearch").css({ display: "inline" });
    // $("#searchIcon").attr("disabled", "disabled");
    $("#input").focus();
    $("#input::after").css({ content: "X", color: "white" });
  });

  $("#searchBox").submit(function(event) {
    $(".mainBox").css({ margin: "5vh !important"});
    
    var queryData = $("#input:first").val();
    console.log(queryData);

    if (queryData != "") {
      ajaxCall(queryData);
    }
  });

  $("#clearSearch").click(function() {
    // $("#searchIcon").css({ display: "inline" });
    
    $("#input").val("");
    // $("form").remove("#input");
    $("#searchResults").html("");
  });
});

function name(variable) {
  array.forEach(element => {});
}

function ajaxCall(keyword) {
  $.ajax({
    url:
      "https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=" +
      keyword +
      "&prop=info&inprop=url&utf8=&format=json",

    dataType: "jsonp",
    success: function(response) {
      $("#searchResults").html("");
      if (response.query.searchinfo.totalhits === 0) {
        showError(keyword);
      } else {
        console.log(response.query);
        console.log(response.query.search);

        response.query.search.forEach(function(x) {
          console.log(x.snippet);
          
          $("#searchResults").append(
            "<div class='result'><a href ='https://en.wikipedia.org/?curid=" +
              x.pageid +
              "' target='blank'> <div class='title'>" +
              x.title +
              "</div><div class='snippet'>" +
              x.snippet +
              "</div></a></div>"
          );
        });
      }
    },
    error: function() {
      alert("Error retrieving search results, please refresh the page");
    }
  });
}

function showError(keyword) {
  console.log("Wikipedia does not have any articles regarding " + keyword);
  return "Wikipedia does not have any articles regarding " + keyword;
}

              
            
!
999px

Console