Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>what am I doing wrong?</p> </blockquote> <p>Using a real <code>&lt;img&gt;</code>.</p> <p>When you use attributes like <code>&lt;img src&gt;</code>, the browser may fix up your values to make them valid. So because the characters <code>{}</code> aren't valid in a URL, the browser may encode them to <code>%7B%7D</code>. This is probably browser-specific; Nick's example that he says works fails for me in Firefox. (It also fails in IE due to the missing <code>var</code> on <code>test_template</code>, but that's an unrelated issue.)</p> <p>Remember when you write HTML elements, the HTML source is not maintained. The browser will parse it into a load of DOM nodes. When you call <code>html()</code> (<code>innerHTML</code>) what you get is a serialisation of those DOM nodes, which does not exactly preserve the formatting of the original markup. Especially when the original markup isn't really valid HTML but just a placeholder for templating.</p> <p>For this reason I would not use actual in-page elements to template from, and I consider jquery-tmpl's encouragement of this with its <code>$(element).template()</code> method to be a mistake. That's not the only issue I with the plugin. For example if you put <code>data()</code> or an event handler on an element inside the template, that data/handler gets copied accidentally on IE but not other browsers, due to naïve <code>innerHTML</code> copying and jQuery's horrid node-identity hack.</p> <p>So if you must use <code>jquery-tmpl</code>, use strings with it, not nodes. Use strings embedded in a <code>&lt;script&gt;</code> if you have to, but don't use actual in-page elements. (As well as this problem, it's also semantically questionable to have content in the document that isn't actual content.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload