0

I need to use jQuery to append an image into a div and although I have read numerous posts, I haven't come with a conclusion.

I have a div call profileIcon and I want in it an image of an that will be loaded using an api. There fore I must load it dynamically.

<div class="profileIcon" id="profile">
   <!--want image here -->
</div>
<script>
var image = "data...";
</script>

Somehow append image an image into .profileIcon, or #profile with a src of the variable img. Any help is appreciated. Thanks in advance. jQuery or JS is fine

1 Answer 1

1

Is this what you want?

    $(document).ready(function() {
      $('button').click(function() {
        $('#profile').append('<img id="theImg" src="https://picsum.photos/200" />');
      });
    });

CodePen

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, please do. :)
Oh and thanks for giving me my first upvote! Double thanks XD
No worries!! :)