我的网站上有一个html元素,它被放在那里超出我的控制,我需要使用javascript/jquery删除它。 HTML标记是一致的,并且在每个页面上,它看起来像这样:使用jquery/javascript删除html标记
<img src="https://myimage.com/myimage.jpg" style="cursor:pointer;border:none;">
如何删除它?该图像没有ID。非常感谢!
我的网站上有一个html元素,它被放在那里超出我的控制,我需要使用javascript/jquery删除它。 HTML标记是一致的,并且在每个页面上,它看起来像这样:使用jquery/javascript删除html标记
<img src="https://myimage.com/myimage.jpg" style="cursor:pointer;border:none;">
如何删除它?该图像没有ID。非常感谢!
您可以像这样删除它:
jQuery("img[src='https://myimage.com/myimage.jpg']").remove();
肯定的是代码在script
标签下面在页面的标记相关的图像。如果图像被动态添加页面标记已经被解析后,你可能要更狡猾:
(function() {
function removeImage() {
var img = jQuery("img[src='https://myimage.com/myimage.jpg']");
if (img.length) {
// It's there now, remove it
img.remove();
}
else {
// Not there yet, check again in a quarter of a second
setTimeout(removeImage, 250);
}
}
removeImage(); // Start the process
})();
注意:您要删除的元素,不是标签。标签是标记(文本)。元素是标签被浏览器解析和创建的结果。
在这里你去
$("img[src='https://www.google.com/images/srpr/logo11w.png']").remove();
http://jsfiddle.net/bowenac/GD64n/
心灵解释什么的图像或张贴活动链接?这将显示删除,但不会解决问题的根源,如果这是某种形式的黑客把这个代码到您的文件...
没有jQuery的,纯JS:
var img = document.querySelector('img[src="https://myimage.com/myimage.jpg"]');
if (img) {
img.parentNode.removeChild(img);
}
其他有您网页上的图像标签? – jmore009
你尝试过什么吗? – j08691
' - >'http://api.jquery.com/category/selectors/attribute-selectors/'<-' –