Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7778009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:17:15+00:00 2026-06-01T18:17:15+00:00

$.each(data, function(i,item){ var img = $(‘<img>’); img.attr(‘src’, item.thumb); img.attr(‘width’, item.width); img.attr(‘height’, item.height); o +=

  • 0
$.each(data, function(i,item){
    var img = $('<img>');
    img.attr('src', item.thumb);
    img.attr('width', item.width);
    img.attr('height', item.height);
    o += '<li><a href="#">'+img+'<h3>'+item.title+'</h3><p>'+item.excerpt+'</p></a></li>';
});

The above outputs

li>[object] <h3>title</h3><p>excerpt</p></li>

My problem is with image tag. I understand that I am just appending a image object rather than the element… and using appendto would work but in the above scenario, in a loop, how do I accomplish this. Instead of displaying [object] how can display the image tag.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:17:19+00:00Added an answer on June 1, 2026 at 6:17 pm

    you have to get the html out of the object. there’s a dozen or more ways to do that. one way is img[0].outerHTML which gives you the raw DOM element in the jQuery selector object, and then the outer html of that element.

    
    $.each(data, function(i,item){
        var img = $('<img>');
        img.attr('src', item.thumb);
        img.attr('width', item.width);
        img.attr('height', item.height);
        o += '<li><a href="#">'+img[0].outerHTML+'<h3>'+item.title+'</h3><p>'+item.excerpt+'</p></a></li>';
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$(.item).each(function(){ var item_link = $(this).find(a).attr(href); $(this).prepend('<div class=img_url></div>'); var img_url = $('div.img_url', this); $.get(item_link, function(data)
var list = []; $.getJSON(json.js, function(data) { $.each(data, function(i, item) { console.log(item.text); list.push(item.text); });
I have this code: $.getJSON(Featured/getEvents, function(data){ $.each(data.events, function(i,event){ var title = event.title.substr(0,20); $(#title-+i).text(Text); if
i have the following code: $.each(data.People, function (i, person) { html.push(<img title=' + person.Name
The code: function updateDashboardData() { $.getJSON(includes/system/ajaxDataInterface.php, {recordcount:1}, function(data) { $('.stationContainer').each(function(data) { var bsID =
$(document).ready(function() { $('#somebutton').click(function() { $.get('List', function(responseJson) { $.each(responseJson, function(index, item) { var elem=$('<input type=checkbox
$.get(CallBack.aspx, { nm: StateTx, nm2: StateTx2 }, function(data) { $.each(data, function() { $('[id$=DropDown1]').append(<option value=
storeChildren : function(coreid, data) { $.each(data, function(id, type) { $.core.children[coreid] = {}; $.core.children[coreid]['id'] =
I have a binary tree function with 3 pieces of data in each node.
We have a script used for each .item : $(.item).each(function(){ item_link = http://...; block

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.