使用Javascript删除没有id或class的div [英] Removing a div with no id or class with Javascript

查看:61
本文介绍了使用Javascript删除没有id或class的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的wordpress博客出现了语法突出显示工具插件的问题,并且弹出了这个奇怪的div元素:

 < div样式="z-index:-1; position:absolute; top:0px; left:0px; width:100%; height:4031px;"></div> 

这会使我的页面扩展,在页面末尾创建一个很大的空间.在每个wordpress博客上也可以找到此内容.有趣的是,只有chrome可以看到(使用Inspect Element).我已经在IE9开发人员工具和FF firebug中尝试过,div不存在,我的页面也很好.

注意:我已经发布了一个单独的问题和

This causes my page to extend, creating a big space at the end of the page. This also is found on every wordpress blog. Funny thing is, only chrome sees that (using Inspect Element). I've already tried in IE9 developer tools and FF firebug, the div is not there and my page is fine.

NOTE: I've already posted a separate question here. And my question here is different from that.

I want to fix this little problem so bad, and it just came to my mind to use JavaScript for this. What I want to do is: Remove the div with javascript.

It's easy removing a div with an ID or class, but this one doesn't have any. I also do not want to affect all the other divs. How can I accomplish this?

P.S. It has no parent IDs or class. It's right after the container class div. It's parent is <body>.

EDIT: Here's the html:

解决方案

If it's always last or close to last you can use jQuery or normal CSS3 selectors

$('body > div:last-child').remove();

OR

$('body > div:nth-last-child(n)').remove();

More on CSS3 Selectors and .remove()

OR you could use CSS i.e.

body > div:last-child (or div:nth-last-child(n)) {
  display: none;
}

这篇关于使用Javascript删除没有id或class的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆