I would like to print the content of a script tag is that possible with jquery?
index.html
<script type="text/javascript"> function sendRequest(uri, handler) { } </script>
Code
alert($("script")[0].???);
result
function sendRequest(uri, handler) { }
You can use native Javascript to do this! External tag can be loaded dynamically instead of inline. Then the code will be inserted between opening and closing tags. It works for me. is there some way to use this method to select script tags that have a specific type attribute?
Adding JavaScript into an HTML DocumentYou can add JavaScript code in an HTML document by employing the dedicated HTML tag <script> that wraps around JavaScript code. 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.
Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.
You can add <script></script> inside a DIV tag. Just check on w3c, it is valid HTML.
Just give your script tag an id:
<div></div> <script id='script' type='text/javascript'> $('div').html($('#script').html()); </script>
http://jsfiddle.net/UBw44/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With