Reputation: 1966
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?
Upvotes: 0
Views: 13975
Reputation: 2265
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();
Upvotes: 0
Reputation: 5416
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.
Upvotes: 2
Reputation: 24312
set a id to your script,
<script id="sample">
...
</script>
and use this code,
$("#sample").remove();
Upvotes: 7