javascriptjqueryscript-tag

Get content inside script as text


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)
{


}

Solution

  • Just give your script tag an id:

    <div></div>
    <script id='script' type='text/javascript'>
        $('div').html($('#script').html());
    </script>
    ā€‹
    

    http://jsfiddle.net/UBw44/