Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

HTML

              
                <body>
  <div class="wrapper">
  <link href="https://fonts.googleapis.com/css?family=Allerta+Stencil&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Bowlby+One+SC&display=swap" rel="stylesheet">

  <img src="https://www.google.com/url?sa=i&source=images&cd=&ved=2ahUKEwjhjpW1yNTlAhXXJzQIHYTCC1MQjRx6BAgBEAQ&url=https%3A%2F%2Fwww.hiclipart.com%2Ffree-transparent-background-png-clipart-fapnp&psig=AOvVaw3xVWMHtaniQU34-hox3O-7&ust=1573094634238973" alt=""><h1>Dad Jokes by Bridget</h1>
  <div id="image">
  </div>
  <a id="random" href="#">CLICK FOR RANDOM DAD JOKE</a>
   <div id="joke">
  </div>
  <br>
  <form id="search-form" action="">
  WANT MORE DAD JOKES?! => <input id="term" type="text" name="term" placeholder="search here :)"><br>
    <br>
  <input id="submit"type="submit" value="CLICK HERE">
    <input type="hidden" name="limit" value="10">
    <input id="current-page" type="hidden" name="page" value="1">
  </form>
  <div id="search-term">
  </div>
  <div id="results">
    
  </div>
  <div id="pagination">
     
  </div>
    </div>
</body>
              
            
!

CSS

              
                body{
  background-color: #FFCC00;
}

.wrapper{
  max-width: 650px;
  margin:auto;
  text-align: center;
}
h1 {
  font-family: 'Bowlby One SC', cursive;
  margin-bottom: 50px;
  font-size: 70px;
}
#random {
  font-family: 'Allerta Stencil', sans-serif;
  text-decoration: none;
  color: black;
  font-size: 30px;
  text-decoration: none;
  border-style: solid;
  border-width: 15px;
  padding: 15px;
}

#random:hover {
  color: white;
  background-color: red;
}

#joke, #results {
  margin-top: 50px;
  font-family: 'Bowlby One SC', cursive;
  font-style: italic;
  letter-spacing: 2px;
}

#results {
  margin-top: 0px;
}

#search-form {
    font-family: 'Allerta Stencil', sans-serif;
  text-decoration: none;
  color: black;
  font-size: 30px;
  text-decoration: none;
  border-style: solid;
  border-width: 15px;
  padding: 15px;
 
}

 #term {
    vertical-align: top;
    height: 30px;
 }

#term:focused {
  outline:none;
}

#submit{
  background-color: black;
  color: #FFCC00;
  width: 100%;
    height: 100px;
  font-size: 30px;
  font-family: 'Bowlby One SC', cursive;
  border: none;
  letter-spacing: 12px;
}

#submit:hover {
  color: red;
  background-color: white;
    border-style: solid;
  border-width: 15px;
}

#submit:focused {
  outline:none;
}

#previous, #next {
  width: 50%;
    margin: auto;
    display: inline-block;
}


#previous input, #next input {
    margin: 0px 10px;
    display: inline-block;
   background-color: black;
  color: #FFCC00;
  width: 100%;
    height: 100px;
  font-size: 30px;
  font-family: 'Bowlby One SC', cursive;
  border: none;
  letter-spacing: 12px;
}
#previous input:hover, #next input:hover {
  color: red;
  background-color: white;
    border-style: solid;
  border-width: 15px;   
}



              
            
!

JS

              
                $('#random').on('click', function(e){
  console.log('hey');
  e.preventDefault(); 
  var url = 'https://icanhazdadjoke.com/';
     $.ajax({
    url : url,
    type : 'GET',
    dataType:'json',
    success : function(data) {              
        console.log(data.joke);
        var joke = JSON.stringify(data.joke);
        var html = '<p>' + joke + '</p>';
        document.getElementById("joke").innerHTML = html;
    },
    error : function(request,error)
    {
       console.log(request, error);
    }
});            
});

$('#search-form').on('submit', function(e){
  e.preventDefault(); 
  var url = 'https://icanhazdadjoke.com/search';
     $.ajax({
    url : url,
    type : 'GET',
    dataType:'json',
    data:$('#search-form').serialize(),
    success : function(data) {              
           add_markup(data);
    },
    error : function(request,error)
    {
       console.log(request, error);
    }
});            
});

$('#pagination').on('submit', '#previous',function(e){
  e.preventDefault(); 
  var url = 'https://icanhazdadjoke.com/search';
     $.ajax({
    url : url,
    type : 'GET',
    dataType:'json',
    data:$('#previous').serialize(),
    success : function(data) {              
            add_markup(data);
    },
    error : function(request,error)
    {
       console.log(request, error);
    }
});            
});

$('#pagination').on('submit', '#next',function(e){
  e.preventDefault(); 
  var url = 'https://icanhazdadjoke.com/search';
     $.ajax({
    url : url,
    type : 'GET',
    dataType:'json',
    data:$('#next').serialize(),
    success : function(data) {              
      add_markup(data);
    },
    error : function(request,error)
    {
       console.log(request, error);
    }
});            
});

function add_markup(data){
          $('current-page').val(data.current_page);
        var results = data.results;
        var testHTML = '';
        $.each(results, function(i, item) {
            console.log(item.joke);
            var test = JSON.stringify(item.joke);
            testHTML = testHTML + '<p>'+ test +'</p>';
            document.getElementById("results").innerHTML = testHTML;
        });
  
        var searchTerm = JSON.stringify(data.search_term);
        if( data.search_term == ""){
          var testing = '<p> ... You searched for ...NOTHING :) but here are some jokes anyways. </p>';
        } else {
           var testing = '<p> ... You searched for ...' + JSON.stringify(data.search_term) + '</p>';
        }
        document.getElementById("search-term").innerHTML = testing;
        
        console.log(data.total_jokes);
        if(data.total_jokes > 11){
                  console.log(data.total_jokes);

        var prev = JSON.stringify(data.previous_page);
        var next = JSON.stringify(data.next_page);
      
        if (data.previous_page == data.current_page){
          document.getElementById("pagination").innerHTML = next_only(searchTerm, next);
        } else if(data.next_page == data.current_page){
           document.getElementById("pagination").innerHTML = previous_only(searchTerm, prev);
        } else {
          document.getElementById("pagination").innerHTML = both_buttons(searchTerm, prev, next);
        }
        }
}

function previous_only(searchTerm, prev){
  return '<form id="previous"><input type="hidden" name="term" value='+ searchTerm +'><br><input type="submit" value="Previous"><input type="hidden" name="limit" value="10"><input id="current-page" type="hidden" name="page" value="'+ prev +'"></form>';
}

function next_only(searchTerm, next){
  return'<form id="next"><input type="hidden" name="term" value='+ searchTerm +'><br><input type="submit" value="Next"><input type="hidden" name="limit" value="10"><input id="current-page" type="hidden" name="page" value="'+ next +'"></form>';
}

function both_buttons(searchTerm, prev, next){
  return '<form id="previous"><input type="hidden" name="term" value='+ searchTerm +'><br><input type="submit" value="Previous"><input type="hidden" name="limit" value="10"><input id="current-page" type="hidden" name="page" value="'+ prev +'"></form><form id="next"><input type="hidden" name="term" value='+ searchTerm +'><br><input type="submit" value="Next"><input type="hidden" name="limit" value="10"><input id="current-page" type="hidden" name="page" value="'+ next +'"></form>';
}
              
            
!
999px

Console