Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does JavaScripts's .innerHTML grab <script> tags?

If you use something like:

var contents = document.getElementById('foobar').innerHTML;

and #foobar contains <script> tags, are the <script> tags included?

EDIT: They are. Proof: http://jsfiddle.net/trusktr/YBzTB/

like image 779
trusktr Avatar asked Mar 15 '11 23:03

trusktr


1 Answers

Yes it does:

JSFiddle Demo

<div id='foobar'><script type='text/javascript'>alert('kewl');</script></div>

var contents = document.getElementById('foobar').innerHTML;
console.log(contents);

Outputs:

<script type="text/javascript">alert('kewl');</script>
like image 153
KJYe.Name Avatar answered Oct 02 '22 22:10

KJYe.Name