i built my own infinitescroll similar to the google image search. Everythings works fine. I only wanted to know if there is another way to append html code in javascript, especially when it is more than one row including javascript functions.
In the moment it loos like this:
appenddiv += '<div class="actbtn">'+
'<a href="javascript:void(0)" onclick="OWNER.feedaction(\''+feedid+'\','action_delete')">'+
'<img id="delicon_'+feedid+'" src="images/icons/delete.gif" title="'+delete_text+'">'+
'</a>'+
'</div>';
Is there another way to do this, cause this is just a very small example. I thought of a function where i can enter "normal" html code without the quotes ' and + and escaping \' etc. and then get the formatted code above.
Normal code:
<div class="actbtn">
<a href="javascript:void(0);" onclick="OWNER.feedaction('{$profile_actions[actions_loop].action_id}','action_delete')">
<img id="delicon_{$profile_actions[actions_loop].action_id}" src="images/icons/delete.gif" title="my text" />
</a>
</div>
I am interesting in your ideas which other ways there are to do this.
-
Can you show how you would call your ideal function (i.e. the one you could enter "normal" html code)?sp00m– sp00m2012年06月22日 09:59:22 +00:00Commented Jun 22, 2012 at 9:59
-
@sp00m edited my post showing what i mean with normal html codeRuven JR. Maerson– Ruven JR. Maerson2012年06月22日 10:05:40 +00:00Commented Jun 22, 2012 at 10:05
3 Answers 3
You could use "JavaScript Micro-Templating" where you add the html in a script tag in semi js format like this:
<script type="text/html" id="user_tmpl">
<% some js %>
some html
</script>
Take a look at John Resigs blog about how you can use it.
4 Comments
1 Comment
You can use jquery html function like $("#parent_div_id").html(appenddiv);
$("#parent_div_id").append(appenddiv);