How to stop and fully remove any executing javascript from a section of page?
I have a page structure as following:
<html>
<head></head>
<body>
<span>
<img src="public/demo.png" />
</span>
<span id="removeWithin">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>Demo Demo</td>
</tr>
<tr>
<td>Demo Demo</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
// there is some javascript logic in here...
</script>
</span>
</body>
</html>
On a button click I would like to fully remove and stop from executing all of the children within the span tag "removeWithin" (remove all of the HTML code + stop and remove all of the JavaScript code). I would like the page to be as such after removal:
<html>
<head></head>
<body>
<span>
<img src="public/demo.png" />
</span>
<span id="removeWithin">
</span>
</body>
</html>
How do I do this?
If I use jQuery's empty() will it automatically stop all of the JavaScript code within the span tag from executing?
$("#removeWithin").empty();
javascript jquery html
add a comment |
I have a page structure as following:
<html>
<head></head>
<body>
<span>
<img src="public/demo.png" />
</span>
<span id="removeWithin">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>Demo Demo</td>
</tr>
<tr>
<td>Demo Demo</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
// there is some javascript logic in here...
</script>
</span>
</body>
</html>
On a button click I would like to fully remove and stop from executing all of the children within the span tag "removeWithin" (remove all of the HTML code + stop and remove all of the JavaScript code). I would like the page to be as such after removal:
<html>
<head></head>
<body>
<span>
<img src="public/demo.png" />
</span>
<span id="removeWithin">
</span>
</body>
</html>
How do I do this?
If I use jQuery's empty() will it automatically stop all of the JavaScript code within the span tag from executing?
$("#removeWithin").empty();
javascript jquery html
2
If the script has already been appended to the page, it's already ran. Removing the markup really won't affect that at all. "If I use jQuery's empty() will it automatically stop all of the JavaScript code within the span tag from executing?" No.
– Taplar
Nov 12 at 15:28
Clearing the node can be done with empty(). But for the javascript, you need to remove all the event listeners you use Before removing the nodes they're tied to. Can you show the JS that needs to get removed so we have an idea how many handlers it contains and if it's doable to remove them all? If there's no event handlers ( like click and such ) , you're probably ok with leaving the script in.
– Shilly
Nov 12 at 15:30
on click:throw new FatalError("!! Stop JavaScript Execution !!");
seriously i dont think this works
– john Smith
Nov 12 at 15:34
add a comment |
I have a page structure as following:
<html>
<head></head>
<body>
<span>
<img src="public/demo.png" />
</span>
<span id="removeWithin">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>Demo Demo</td>
</tr>
<tr>
<td>Demo Demo</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
// there is some javascript logic in here...
</script>
</span>
</body>
</html>
On a button click I would like to fully remove and stop from executing all of the children within the span tag "removeWithin" (remove all of the HTML code + stop and remove all of the JavaScript code). I would like the page to be as such after removal:
<html>
<head></head>
<body>
<span>
<img src="public/demo.png" />
</span>
<span id="removeWithin">
</span>
</body>
</html>
How do I do this?
If I use jQuery's empty() will it automatically stop all of the JavaScript code within the span tag from executing?
$("#removeWithin").empty();
javascript jquery html
I have a page structure as following:
<html>
<head></head>
<body>
<span>
<img src="public/demo.png" />
</span>
<span id="removeWithin">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>Demo Demo</td>
</tr>
<tr>
<td>Demo Demo</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
// there is some javascript logic in here...
</script>
</span>
</body>
</html>
On a button click I would like to fully remove and stop from executing all of the children within the span tag "removeWithin" (remove all of the HTML code + stop and remove all of the JavaScript code). I would like the page to be as such after removal:
<html>
<head></head>
<body>
<span>
<img src="public/demo.png" />
</span>
<span id="removeWithin">
</span>
</body>
</html>
How do I do this?
If I use jQuery's empty() will it automatically stop all of the JavaScript code within the span tag from executing?
$("#removeWithin").empty();
javascript jquery html
javascript jquery html
asked Nov 12 at 15:25
ajmusiclion
113
113
2
If the script has already been appended to the page, it's already ran. Removing the markup really won't affect that at all. "If I use jQuery's empty() will it automatically stop all of the JavaScript code within the span tag from executing?" No.
– Taplar
Nov 12 at 15:28
Clearing the node can be done with empty(). But for the javascript, you need to remove all the event listeners you use Before removing the nodes they're tied to. Can you show the JS that needs to get removed so we have an idea how many handlers it contains and if it's doable to remove them all? If there's no event handlers ( like click and such ) , you're probably ok with leaving the script in.
– Shilly
Nov 12 at 15:30
on click:throw new FatalError("!! Stop JavaScript Execution !!");
seriously i dont think this works
– john Smith
Nov 12 at 15:34
add a comment |
2
If the script has already been appended to the page, it's already ran. Removing the markup really won't affect that at all. "If I use jQuery's empty() will it automatically stop all of the JavaScript code within the span tag from executing?" No.
– Taplar
Nov 12 at 15:28
Clearing the node can be done with empty(). But for the javascript, you need to remove all the event listeners you use Before removing the nodes they're tied to. Can you show the JS that needs to get removed so we have an idea how many handlers it contains and if it's doable to remove them all? If there's no event handlers ( like click and such ) , you're probably ok with leaving the script in.
– Shilly
Nov 12 at 15:30
on click:throw new FatalError("!! Stop JavaScript Execution !!");
seriously i dont think this works
– john Smith
Nov 12 at 15:34
2
2
If the script has already been appended to the page, it's already ran. Removing the markup really won't affect that at all. "If I use jQuery's empty() will it automatically stop all of the JavaScript code within the span tag from executing?" No.
– Taplar
Nov 12 at 15:28
If the script has already been appended to the page, it's already ran. Removing the markup really won't affect that at all. "If I use jQuery's empty() will it automatically stop all of the JavaScript code within the span tag from executing?" No.
– Taplar
Nov 12 at 15:28
Clearing the node can be done with empty(). But for the javascript, you need to remove all the event listeners you use Before removing the nodes they're tied to. Can you show the JS that needs to get removed so we have an idea how many handlers it contains and if it's doable to remove them all? If there's no event handlers ( like click and such ) , you're probably ok with leaving the script in.
– Shilly
Nov 12 at 15:30
Clearing the node can be done with empty(). But for the javascript, you need to remove all the event listeners you use Before removing the nodes they're tied to. Can you show the JS that needs to get removed so we have an idea how many handlers it contains and if it's doable to remove them all? If there's no event handlers ( like click and such ) , you're probably ok with leaving the script in.
– Shilly
Nov 12 at 15:30
on click:
throw new FatalError("!! Stop JavaScript Execution !!");
seriously i dont think this works– john Smith
Nov 12 at 15:34
on click:
throw new FatalError("!! Stop JavaScript Execution !!");
seriously i dont think this works– john Smith
Nov 12 at 15:34
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265242%2fhow-to-stop-and-fully-remove-any-executing-javascript-from-a-section-of-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265242%2fhow-to-stop-and-fully-remove-any-executing-javascript-from-a-section-of-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
If the script has already been appended to the page, it's already ran. Removing the markup really won't affect that at all. "If I use jQuery's empty() will it automatically stop all of the JavaScript code within the span tag from executing?" No.
– Taplar
Nov 12 at 15:28
Clearing the node can be done with empty(). But for the javascript, you need to remove all the event listeners you use Before removing the nodes they're tied to. Can you show the JS that needs to get removed so we have an idea how many handlers it contains and if it's doable to remove them all? If there's no event handlers ( like click and such ) , you're probably ok with leaving the script in.
– Shilly
Nov 12 at 15:30
on click:
throw new FatalError("!! Stop JavaScript Execution !!");
seriously i dont think this works– john Smith
Nov 12 at 15:34