Appending image dynamically

Image container


Using block-box cover flex-box:

  • block-box has height or width
  • flex-box has flex-direction and height or width

Using jQuery to append image into container


var img = $('');
img.attr('src', 'the address of img');
img.css({"height": "100%", "width": "auto%"});
img.appendTo('#container');

Or using jQuery to remove image from container


var iconName= 'the name of icon';
$('img').each(function(i, el){
  if($(this).attr('src').indexOf(iconName) > -1){
    $(this).remove();
  }
});

Here is my code with bootstrap 4

icon.png







你可能感兴趣的:(Appending image dynamically)