Reputation: 1230
I am trying to set the src
of img
tag dynamically with backbone templating, but /
is appended automatically for which img
not loaded.The part of template looks like -
<script type="text/template" id="home">
.......
<% var d=names[0].get("image_link")+".jpg"
//d=d.substring(0 , d.length-1); tried to cut down last char
%>
<a href="#" class="thumbnail"><img class="img-responsive ui-corner-all" width="100%" height="auto" src=<%=d%> />
.......
</script>
The output -
<a href="#" class="thumbnail"><img class="img-responsive ui-corner-all" width="100%" height="auto" src="image1.jpg/" />
I couldn't figure it out how to exclude that /
in img
src. Any suggestion please.
Upvotes: 0
Views: 641
Reputation: 700680
That slash is actually there in the code. As you don't have any quotation marks around the attribute value, the /
in />
becomes part of the value.
Add quotation marks:
<a href="#" class="thumbnail"><img class="img-responsive ui-corner-all" width="100%" height="auto" src="<%=d%>" />
Upvotes: 3