开发者

Where to store html code for jQuery?

In some scripts long html blocks are added to selector. For example

$("#test").prepend($('<div id="tester">..long html tags..</div>').hide().fadeIn(2000));

Where it woul开发者_JS百科d be better to store that large html blocks? Directly, in variable, in html code, text file or other.

Thank you.


have you had a look at jquery templates?


If they are static I think it would be better to have them as separate XML files and get them with an AJAX call to let them be cached.


Because javascript (therefor jquery) is interpreted code it does not really matter from a perfomance perspective. "Better" becomes a subjective choice and with that it becomes a question of readablity and reusablity. If you have text patterns that are going to be reused then you definitly want to use some manner of template. After that it is purely dealers' choice.


If that long html is not dynamic, then you can put them(div) into your main html itself and make it as hidden.

   <div id="testerouter" style="display:none>
     <div id="tester">..long html tags..</div>
   </div>

then you can able to retrieve them using

 $("#testerouter").html();

and prepend with your id(test)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜