Inhibit script code belong from some items

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Aegidius
Forum Newbie
Posts: 3
Joined: Thu Apr 28, 2011 1:07 pm

Inhibit script code belong from some items

Post 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?
KCAstroTech
Forum Commoner
Posts: 33
Joined: Sat Aug 27, 2011 11:16 pm

Re: Inhibit script code belong from some items

Post 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
Post Reply