Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<script> tag inside jquery template

Tags:

Backgroud:

I have this template that includes videos from youtube being loaded with swfobject.

Question:

Is there a way to include a script tag...

<script type="text/javascript"> </script> 

inside a jQuery Template??

<script id="filaVideoTemplate" type="text/x-jQuery-tmpl">     <!-- Some HTML here -->     <script type="text/javascript">         <!-- Some javascript here -->     </script> </script> 

Obviously it doesn't work directly, is there any way to achive the same thing without the script inside other script?

like image 686
Carlos Muñoz Avatar asked Jan 24 '11 23:01

Carlos Muñoz


People also ask

Can we write jQuery in script tag?

In the web page write your jQuery code within document ready state in the <script > tag. In the example, I used CDN library and defined click event on the button. On the click change value of the textbox element.

Is script tag inside body?

The <script> tag can be placed in the <head> section of your HTML or in the <body> section, depending on when you want the JavaScript to load. Generally, JavaScript code can go inside of the document <head> section in order to keep them contained and out of the main content of your HTML document.

When to use template tag?

The <template> tag is used as a container to hold some HTML content hidden from the user when the page loads. The content inside <template> can be rendered later with a JavaScript. You can use the <template> tag if you have some HTML code you want to use over and over again, but not until you ask for it.

What is template element in HTML?

The <template> HTML element is a mechanism for holding HTML that is not to be rendered immediately when a page is loaded but may be instantiated subsequently during runtime using JavaScript. Think of a template as a content fragment that is being stored for subsequent use in the document.


1 Answers

<script id="filaVideoTemplate" type="text/x-jQuery-tmpl">     <!-- Some HTML here -->     <script type="text/javascript">         <!-- Some javascript here -->     {{html "</sc"+"ript>"}} </script> 

You can use {{html "</sc"+"ript>"}} replace </script>

like image 77
Ronny Wang Avatar answered Sep 20 '22 14:09

Ronny Wang