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 8947831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:52:02+00:00 2026-06-15T12:52:02+00:00

I have been using the $.each function and some templating so that I can

  • 0

I have been using the $.each function and some templating so that I can effectively populate/replace my HTML string stored in the temp variable with the title and thumbnail property of the objects stored in the content array.

So for example within the callback function of $.each a regular expression finds the {{title}}, it will replace {{title}} with the contents of obj.title, so that we essentially replace it with the string ‘Speak of the devil and he shall appear’ which is the title property of the object which is iterated over.

The problem I have found is that when I come to append this HTML string (temp variable) to the body. My img HTML tag has been outputted in the wrong way and the contents of obj.title are creating undesired attributes in my img tag

HTML outputted:

<h2> Speak of the devil and he shall appear </h2>
<img appear="" shall="" he="" and="" devil="" the="" of="" alt="Speak" src="images/bane.jpg">

Here is my template:

<script id="blogTemplate" type="chris/template">
    <h2> {{title}} </h2>
    <img src={{thumbnail}} alt={{title}}>
</script>

And here is my jQuery code:

(function() {

        var content = [
            {
                title: 'Speak of the devil and he shall appear',   
                thumbnail: 'images/bane.jpg',
            },

            {
                title: 'Me the joker',   
                thumbnail: 'images/Joker.jpg',
            }
        ];

            var template = $.trim( $('#blogTemplate').html() );

        $.each( content, function( index, obj ) {  

            var temp = template.replace( /{{title}}/ig, obj.title )
                               .replace( /{{thumbnail}}/ig, obj.thumbnail );
            console.log(temp);

            $('body').append(temp);
        });

    })();
  • 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-15T12:52:04+00:00Added an answer on June 15, 2026 at 12:52 pm

    You need to modify your template to include quotes around the attributes.

    <script id="blogTemplate" type="chris/template">
        <h2> {{title}} </h2>
        <img src="{{thumbnail}}" alt="{{title}}">
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using dojo 1.8 framework to create a widget that includes some
I have been using TortoiseSVN for some time and I really like it. I
I have been using an API to do some work. This is how I
I have been using some Javascript to create a text field once an certain
I have been using this function for a while without a problem, although I
I have been using Microsoft Outlook and WindowsMobile devices for some years now. But
I have some differential equations that I need to solve using MATLAB's ODE solvers.
I have a JQuery code I have been using for some time however today
Hi, i have been having some problems using JSON data in flash builder lately
I have been using data.table for some computation and am wondering what are the

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.