0

I am able to remove html element using jquery using $(element).remove();. But there is a javascript code, like setinterval(), which should be removed. Yes, I can do clearInterval() for particular that case, but what if other types of javascript code?

     <script>
     var baseurl = '...';
     jQuery(function(){
        new AjaxUpload('#upload_button', {
           action: baseurl,
           onSubmit : function(file , ext){
              jQuery('#...').val(file);
           },
           onComplete: function(file, response){
              // do something....;
           }
        });
     });
     </script>

But I am unable to do so.

Can anybody help me out this problem?

6
  • 1
    What other types of code? Why do you want to do that? Commented Jan 10, 2012 at 6:18
  • Are you referring to event handlers that were bound to the removed elements? Commented Jan 10, 2012 at 6:24
  • like some jquery event handler within a script block Commented Jan 10, 2012 at 6:26
  • 1
    Edit your question and show examples! Commented Jan 10, 2012 at 6:32
  • I have edited. Please look at the question again. Commented Jan 10, 2012 at 6:42

3 Answers 3

7

set a id to your script,

<script id="sample">
...
</script>

and use this code,

$("#sample").remove();
Sign up to request clarification or add additional context in comments.

4 Comments

Let me try, I will inform you as soon as possible.
thanks for the down voter for down voting without any comment in accepted answer :)
Hey @Chamika, Don't know, who down-voted you, but the thing is that, your answer is perfect and really worked for me, and is the answer I was searching for.
@SoumalyaBanerjee: I know that you are not the person who downvoted. i just put that comment to inform him, it is always better to put a comment when some one down voting. at least for a accepted answer :)
2

I'm not sure what exactly you're trying to achieve but in general, removing Javascript code from the document is not the correct way to "switch off" certain functionality you have enabled via Javascript.

For example, if you have set event handlers on certain links and want to undo them, you should use the off function. Similarly, there would be a way to "undo" everything you've added.

Comments

0

There is a way to wrap response in div element and remove all script tags,

var el = $('<div>'+response+'</div>');
$('script', el).remove();
response = el.html();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.