[Solved] jQuery add html content in hidden div [closed]


You can use jQuery’s hide() and show() function to accomplish this, which is a little cleaner than the .css() ZeJur used. Have a look at my Plunker example

Example:

<div class="hiddenContent">I am hidden div</div>    
<button class="addDynamicContent">Add dynamic content to div - hide while doing</button>

Script:

<script>
$('.addDynamicContent').click(function() {
        $.ajax({
          url: "http://api.icndb.com/jokes/random",
          beforeSend: function() {
            $('.hiddenContent').hide();
            console.log('I hide before request');
          },
          success: function(response) {
            $('.hiddenContent').html(response.value.joke);
            $('.hiddenContent').show();
            console.log('I show after I got the content');
          }
        });
      });
</script>

Check out Plunker

solved jQuery add html content in hidden div [closed]