开发者

jQuery output after the script

My jQuery script creates a form. I need the form to appear just before the script :

<script type="text/javascript" src="..."></script>
//the form appears here...

This previous line will appear on various sites so I cannot insert/append.. it to an element $('element')... it would need to be : $('current script').prepend('...')

I would like users to be able to insert the script where they want the form to appear

How can I achi开发者_如何学Ceve this?


If I understand your question right...

$('script[src="your/path"]').after(element);

where element is what you're inserting.

http://api.jquery.com/attribute-equals-selector/
http://api.jquery.com/after/


Usually you're using document.write() to achieve this(google is doing this for example when inserting pageads)


You can insert a placeholder with document.write() and the use jQuery to place the form into the palceholder. So your script could look like this:

document.write('<div id="placeholderForForm"></div>");

$('#placeholderForForm').xx(...);

Even easier is probably to insert large pieces of the form with document.write().

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜