Hitesh Chauhan
Hitesh Chauhan

Reputation: 87

how to add src of image using jquery append function?

add src of image using jquery append function. i am using a variable in foreach loop and i wants to append image src . how do i do that.

my jquery code

$.each(data.products, function(key,val) {
  $("div#yourwishlist").append('<div class="col-sm-6 col-md-4"><article class="box"><figure><a class="hover-effect" title="" href="#"><img width="300" height="160" alt="" src="'+val('thumb')+'"></a></figure><div class="details"><a class="pull-right button uppercase" href="" title="View all">select</a><h4 class="box-title">'+val['name']+'</h4><label class="price-wrapper"><span class="price-per-unit">$170</span>avg/night</label></div></article></div>');
console.log(val['name']);
});

this code is not working in my case ...

Upvotes: 0

Views: 358

Answers (1)

Mayank Pandeyz
Mayank Pandeyz

Reputation: 26258

Hitesh you can add src attribute to an image like:

$.each(data.products, function(key,val) {
   $("div#yourwishlist").append('<img width="300" height="160" alt="" src="'+ val +'">');
});

// here val contains the path of image in it

Upvotes: 1

Related Questions