0

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.

2
  • Can you show how you would call your ideal function (i.e. the one you could enter "normal" html code)? Commented Jun 22, 2012 at 9:59
  • @sp00m edited my post showing what i mean with normal html code Commented Jun 22, 2012 at 10:05

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

4 Comments

ah this is what i meant before. hm interesting. you ve tried it?
I have, yes, I found it a great way to separate html templates from actual js code.
I will give it a try. i am wondering if the conversion is fast and without errors expecially when it includes js like in my example.
I don't see any reason why your example shouldn't work, my implementation had some pretty complicated parts in it but it all worked fast and flawless so far.
0

In Jquery, you could use:

.append();

.html();

1 Comment

i know. Im just interested in other ways to append html code. not how to do this generally.
0

You can use jquery html function like $("#parent_div_id").html(appenddiv);

$("#parent_div_id").append(appenddiv);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.