admin管理员组

文章数量:1278978

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?

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?

Share Improve this question edited Jan 10, 2012 at 7:03 nnnnnn 150k30 gold badges209 silver badges247 bronze badges asked Jan 10, 2012 at 6:17 Soumalya BanerjeeSoumalya Banerjee 1,9663 gold badges22 silver badges28 bronze badges 6
  • 1 What other types of code? Why do you want to do that? – Sergio Tulentsev Commented Jan 10, 2012 at 6:18
  • Are you referring to event handlers that were bound to the removed elements? – nnnnnn Commented Jan 10, 2012 at 6:24
  • like some jquery event handler within a script block – Soumalya Banerjee Commented Jan 10, 2012 at 6:26
  • 1 Edit your question and show examples! – epascarello Commented Jan 10, 2012 at 6:32
  • I have edited. Please look at the question again. – Soumalya Banerjee Commented Jan 10, 2012 at 6:42
 |  Show 1 more ment

3 Answers 3

Reset to default 7

set a id to your script,

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

and use this code,

$("#sample").remove();

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.

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();

本文标签: jquery remove javascript codeStack Overflow