Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 删除动态添加的元素_Javascript_Jquery - Fatal编程技术网

Javascript 删除动态添加的元素

Javascript 删除动态添加的元素,javascript,jquery,Javascript,Jquery,我试图删除动态添加到标记末尾的样式表 出于某些原因,我不得不使用javascript删除样式表标签并添加我自己的标签 这是我试过的代码- jQuery(document).ready(function(){ jQuery('link[href^="somepath/editor.css"]').remove(); jQuery('head').append("<link href='somepath/custom/editor.css' type='text/css' rel='style

我试图删除动态添加到
标记末尾的样式表

出于某些原因,我不得不使用javascript删除样式表标签并添加我自己的标签

这是我试过的代码-

jQuery(document).ready(function(){
jQuery('link[href^="somepath/editor.css"]').remove();
jQuery('head').append("<link href='somepath/custom/editor.css' type='text/css' rel='stylesheet' />");
});
jQuery(文档).ready(函数(){
jQuery('link[href^=“somepath/editor.css”]”)。删除();
jQuery('head')。追加(“”);
});
问题是此函数在CkEditor函数之前执行。因此,我的样式表被添加到ckeditor样式表和ckeditor样式表之前 我尝试使用
.load
而不是
.ready
,但是代码似乎根本没有运行


有什么帮助吗?

如果你不知道什么时候会添加css,你可以使用setInterval进行轮询

var interval = setInterval(function(){
    var css = jQuery('link[href^="somepath/editor.css"]')
    if (css.length){
        css.remove();
        jQuery('head').append("<link href='somepath/custom/editor.css' type='text/css' rel='stylesheet' />");
        clearIntrval(interval);
    }
}, 500);
var interval=setInterval(函数(){
var css=jQuery('link[href^=“somepath/editor.css”]”)
if(css.length){
css.remove();
jQuery('head')。追加(“”);
clearIntrval(间隔);
}
}, 500);