cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-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.

            
              <body>
  <div class="container">
    <h2 class="quoteText" id="quoteText"> Loading Quote...
  </h2>
    <p class="quoteAuthor">- Unknown</p>
    <button class="button" id="newQuote"> New Quote</button>
    <a href="" target="_blank" class="button twitter-share-button"><i class="fa fa-twitter fa-2x" aria-hidden="true"></i></a>
  </div>
  <div class="footer">Inspired by FCC, coded by Alexandre Robin</div>
</body>
            
          
!
            
              body{
  background-color:#0097A7;
  padding-top:10%;
}
.container{
  background-color:white;
  color:#0097A7;
  text-align:justify;
  margin:auto;
  padding:50px;
  width:50%;
  display:block;
  border:none;
  border-radius:5px;
}
.quoteAuthor{
  text-align:right;
  font-style:italic;
}
.twitter-share-button{
  float:right;
  color:#fff;
}
a {
  color:#fff;
}
a:hover {
  opacity:0.8;
  color:white;
}
.button {
      height:38px;
      border:none;
      border-radius:3px;
      color:#fff;
      background-color:#0097A7;
      outline:none;
      font-size:0.85em;
      padding: 8px 18px 6px 18px;
      margin-top:30px;
      opacity:1;
      cursor:pointer;
}
.button:hover{
  opacity:0.8;
}
.footer{
  text-align:center;
  font-size:0.8em;
  margin-top:10px;
  padding-bottom:10%;
  color:#006064;
}

            
          
!
            
              $(function() {

  // Event listener : onClick New Quote button
  $("#newQuote").click(function() {
    getNewQuote();
  });
  /*$(".twitter-share-button").click(function() {
    $(".twitter-share-button").html("<a href='https://twitter.com/' target='_blank'><a>");
  })*/

  // Main function  
  function getNewQuote() {

    //I had an issue with the cache and the API, so this is a workaround found on StackOverflow : I set a timestamp value with Date().getTime(). This allow me to have a new http request every time I launch getNewQuote(). A bit slower, but it works :) 
    var timestamp = new Date().getTime();
    var apiURL = "https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&timestamp=" + timestamp;

    // Get the JSON data from API with the url witch has been built before and push it to the HTML
    $.getJSON(apiURL, function(json) {
      var content = json[0].content.replace(/<\/?p[^>]*>/g, "");
      $(".quoteText").html(content);
      var author = json[0].title === "" ? "Unknown" : json[0].title;
      $(".quoteAuthor").html("- " + author);
      var textForLink = encodeURIComponent(content);
      var link = "https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=" + textForLink;
      $(".twitter-share-button").attr("href", link);

    });

  };
  getNewQuote();
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console