��权限没有,则隐藏 function forum_list_access_filter($forumlist, $gid, $allow = 'allowread') { global $grouplist; if (empty($forumlist)) return array(); if (1 == $gid) return $forumlist; $forumlist_filter = $forumlist; $group = $grouplist[$gid]; foreach ($forumlist_filter as $fid => $forum) { if (empty($forum['accesson']) && empty($group[$allow]) || !empty($forum['accesson']) && empty($forum['accesslist'][$gid][$allow])) { unset($forumlist_filter[$fid]); } unset($forumlist_filter[$fid]['accesslist']); } return $forumlist_filter; } function forum_filter_moduid($moduids) { $moduids = trim($moduids); if (empty($moduids)) return ''; $arr = explode(',', $moduids); $r = array(); foreach ($arr as $_uid) { $_uid = intval($_uid); $_user = user_read($_uid); if (empty($_user)) continue; if ($_user['gid'] > 4) continue; $r[] = $_uid; } return implode(',', $r); } function forum_safe_info($forum) { //unset($forum['moduids']); return $forum; } function forum_filter($forumlist) { foreach ($forumlist as &$val) { unset($val['brief'], $val['announcement'], $val['seo_title'], $val['seo_keywords'], $val['create_date_fmt'], $val['icon_url'], $val['modlist']); } return $forumlist; } function forum_format_url($forum) { global $conf; if (0 == $forum['category']) { // 列表URL $url = url('list-' . $forum['fid'], '', FALSE); } elseif (1 == $forum['category']) { // 频道 $url = url('category-' . $forum['fid'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = url('read-' . trim($forum['brief']), '', FALSE); } if ($conf['url_rewrite_on'] > 1 && $forum['well_alias']) { if (0 == $forum['category'] || 1 == $forum['category']) { $url = url($forum['well_alias'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = ($forum['threads'] && $forum['brief']) ? url($forum['well_alias'] . '-' . trim($forum['brief']), '', FALSE) : url($forum['well_alias'], '', FALSE); } } return $url; } function well_forum_alias() { $forumlist = forum_list_cache(); if (empty($forumlist)) return ''; $key = 'forum-alias'; static $cache = array(); if (isset($cache[$key])) return $cache[$key]; $cache[$key] = array(); foreach ($forumlist as $val) { if ($val['well_alias']) $cache[$key][$val['fid']] = $val['well_alias']; } return array_flip($cache[$key]); } function well_forum_alias_cache() { global $conf; $key = 'forum-alias-cache'; static $cache = array(); // 用静态变量只能在当前 request 生命周期缓存,跨进程需要再加一层缓存:redis/memcached/xcache/apc if (isset($cache[$key])) return $cache[$key]; if ('mysql' == $conf['cache']['type']) { $arr = well_forum_alias(); } else { $arr = cache_get($key); if (NULL === $arr) { $arr = well_forum_alias(); !empty($arr) AND cache_set($key, $arr); } } $cache[$key] = empty($arr) ? '' : $arr; return $cache[$key]; } ?>html - Removing a div with no id or class with Javascript - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Removing a div with no id or class with Javascript - Stack Overflow

programmeradmin4浏览0评论

My wordpress blog is having issues with syntax highlighter evolved plugin, and there's this weird div element popping out:

<div style="z-index: -1; position:absolute; top:0px; left: 0px; width: 100%; height: 4031px;"></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 acplish 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:

My wordpress blog is having issues with syntax highlighter evolved plugin, and there's this weird div element popping out:

<div style="z-index: -1; position:absolute; top:0px; left: 0px; width: 100%; height: 4031px;"></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 acplish 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:

Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 11 silver badge asked Nov 23, 2010 at 6:44 RuelRuel 15.8k7 gold badges40 silver badges49 bronze badges 7
  • Can you provide some context to it? Do any parent elements have an id. Is it in a unique nesting level, i.e. no other div siblings? – alex Commented Nov 23, 2010 at 6:47
  • Are you sure that the tag attributes are in the text-node (ie: between the start and end tag)? – Mathew Commented Nov 23, 2010 at 6:49
  • @alex It has no parent IDs or class. It's right after the container class div. It's parent is <body>. – Ruel Commented Nov 23, 2010 at 6:51
  • Note that your screenshot shows a div with the attributes in the correct place, not as text. Your quoted code at the top of your question shows the attributes as content within the div. Is that a typo? – T.J. Crowder Commented Nov 23, 2010 at 7:10
  • @T.J. Crowder typo, sorry.. Can't copy directly from chrome element inspector. :) – Ruel Commented Nov 23, 2010 at 7:16
 |  Show 2 more ments

4 Answers 4

Reset to default 3

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;
}

You could do something like this:

var els = document.getElementsByTagName('div');
for (var i = 0; l = els.length; i < l; i++) {
  if (els[i].innerHTML == 'style....') {
    els[i].parentNode.removeChild(els[i]);
  }
}

If you are using jQuery, You can reference the div using a parent or sibling div that might have an ID or class defined.

For examample :

<div id="parentDIVID">

  <div>your problem div</div>

</div>


Then you can use jQuery to reference your problem div like this : $("#parentDIVID > div")

If you can provide more html code surrounding your problem div, we can construct a jQuery selector that will work in your case.

Update : Based on the markup provided

function removeDiv() {

    var parent = document.getElementById("stimuli_overlay").parentNode;

    var children = document.getElementById("stimuli_overlay").parentNode.childNodes;

    for (var i = 0; i < children.length; i++) {

        if (children[i].style.zIndex == -1)
            parent.removeChild(children[i]);
    }


}

Update: Based on the fact that you can't rely on the div used below.

If the div really is the always the last div in the document, this is actually easier:

var divs, div;
divs = document.getElementsByTagName("div");
if (divs.length > 0) {
    div = divs.item(divs.length - 1);
    div.parentNode.removeChild(div);
}

Live example

length - 1 will remove the last div in the document. If you needed to skip a lightbox div or something, adjust to use - 2 or - 3, etc.

Old Answer using the earlier information:

Given that structure, something along these lines:

// Get the div that follows it, which conveniently has an ID
var div = document.getElementById('stimuli_overlay');

// If that worked...
if (div) {
    // ...move to the previous div, with a bit of paranoia about blank non-element
    // nodes in-between
    div = div.previousSibling;
    while (div && (div.nodeType !== 1 || div.tagName !== "DIV")) {
        div = div.previousSibling;
    }

    // Check that this really is the right div
    if (div && div.tagName === "DIV"
        // The following checks look for some of the style properties that your
        // screenshot shows are set on the div
        && div.style.position == "absolute"
        && div.style.zIndex == "-1"
        && div.style.top == "0px"
        && div.style.left == "0px"
        && div.style.width == "100%"
        && /* ...possibly more checks here... */) {
        // Remove it
        div.parentNode.removeChild(div);
    }
}

发布评论

评论列表(0)

  1. 暂无评论