Load image with jQuery and append it to the DOM

前端 未结 6 1081
执念已碎
执念已碎 2020-11-27 03:54

I\'m trying to load an image from a given link

var imgPath = $(imgLink).attr(\'href\');

and append it to the page, so I can insert it i

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 04:08

    $('').load(function() {
      $(this).width(some).height(some).appendTo('#some_target');
    });
    

    If you want to do for several images then:

    function loadImage(path, width, height, target) {
        $('').load(function() {
          $(this).width(width).height(height).appendTo(target);
        });
    }
    

    Use:

    loadImage(imgPath, 800, 800, '#some_target');
    

提交回复
热议问题