Page 1 of 1

Inhibit script code belong from some items

Posted: Wed Aug 31, 2011 4:54 am
by Aegidius
Is it possible to inhibit the execution of script code that belong from some HTML elements?

For example if I have this code

Code: Select all

<div id="my_div">
<script>
alert("please don't show me");
</script>
</div>
there is a jQuery or JavaScipt function that makes the script in that div not executable?

Re: Inhibit script code belong from some items

Posted: Thu Sep 08, 2011 11:48 pm
by KCAstroTech
If the script is on the page at load time then as far as I understand the browser will execute it. If you try and put some javascript higher on the page before that element is added to the document then there isn't anyway to address that div element as it technically doesn't exist yet. Yet if you put something after or below the element then at that point the browser would have already added the element and executed the script within it.

However, if you are using the .append() or .load() functions then you should be able to check the contents of what you are appending or loading and remove any scripts in it prior to appending or loading it into the target element. :D