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
3 Answers
Reset to default 7set 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
版权声明:本文标题:jquery remove javascript code - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741243290a2364398.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论