Javascript-форум (https://javascript.ru/forum/)
-   Events/DOM/Window (https://javascript.ru/forum/events/)
-   -   удалить родительский объект изнутри через onClick (https://javascript.ru/forum/events/30692-udalit-roditelskijj-obekt-iznutri-cherez-onclick.html)

Brook 12.08.2012 16:46

удалить родительский объект изнутри через onClick
 
Доброго времени суток, уважаемые форумчане!
Помоги пожалуйста с решением вопроса:

<div id="bigorsite">
<span style="width:140px;height:40px;background:url(/images/minS/konfortxt.png);display:block;float:left;margin:60px 0 0 140px;color:#fff;font-size:30px;padding:5px 0;" onmouseover="this.style.margin='40px 0 0 140px'" onmouseout="this.style.margin='60px 0 0 140px'" align="center">ФОТО</span>
<span style="width:140px;height:40px;background:url(/images/minS/konfortxt.png);display:block;margin:60px 0 0 10px;float:left;padding:5px 0;color:#fff;font-size:30px;" onmouseover="this.style.margin='40px 0 0 10px'" onmouseout="this.style.margin='60px 0 0 10px'" align="center">САЙТ</span><span onclick="document.body.parentNode.removeChild(document.getElementById('bigorsite'))" style="width:40px;height:40px;background:url(/images/minS/exitfromini.png);display:block;float:left;margin:60px 0 0 855px;z-index:99;position:absolute;">
pp</span>
<div style="position:absolute;z-index:9;background:url(/images/minS/fonfortxt.png);width:750px;height:750px;margin:79px 125px;display:block;opacity:1 !important;filter:alpha(Opacity=100) !important;">fg</div>
</div>


Я пробую с помощью этой "кнопки" закрыть bigorsite - основной блок - но, у меня не выходит.

Вот кнопка(тот же код сверху, вынес для упрощения чтения):
<span onclick="document.body.parentNode.removeChild(document.getElementById('bigorsite'))" style="width:40px;height:40px;background:url(/images/minS/exitfromini.png);display:block;float:left;margin:60px 0 0 855px;z-index:99;position:absolute;">
pp</span>

Brook 12.08.2012 16:47

Заранее - извините за столь грязный код.

Deff 12.08.2012 16:53

<!DOCTYPE html>
  <html>
    <head>
      <meta charset="utf-8">
      <title>Пример страницы</title>
      <link href="reset.css" rel="stylesheet" type="text/css">
      <link href="style.css" rel="stylesheet" type="text/css">
    </head>
    <body>

      <div id="bigorsite">

        <span style="width: 140px; height: 40px; background-attachment: scroll; background-repeat: repeat; background-image: url(&quot;http://forum.mybb.ru/images/minS/konfortxt.png&quot;); background-position: 0% 0%; background-size: auto; background-origin: padding-box; background-clip: border-box; background-color: transparent; display: block; float: left; margin-right: 0px; margin-bottom: 0px; margin-left: 140px; color: rgb(255, 255, 255); font-size: 30px; padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; margin-top: 60px" onmouseover="this.style.margin='40px 0 0 140px'" onmouseout="this.style.margin='60px 0 0 140px'" align="center">ФОТО</span>

        <span style="width: 140px; height: 40px; background-attachment: scroll; background-repeat: repeat; background-image: url(&quot;http://forum.mybb.ru/images/minS/konfortxt.png&quot;); background-position: 0% 0%; background-size: auto; background-origin: padding-box; background-clip: border-box; background-color: transparent; display: block; margin-right: 0px; margin-bottom: 0px; margin-left: 10px; float: left; padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; color: rgb(255, 255, 255); font-size: 30px; margin-top: 60px" onmouseover="this.style.margin='40px 0 0 10px'" onmouseout="this.style.margin='60px 0 0 10px'" align="center">САЙТ</span>

        <span onclick="a=document.getElementById('bigorsite');a.parentNode.removeChild(a)" style="width:40px;height:40px;background:url(/images/minS/exitfromini.png);display:block;float:left;margin:60px 0 0 855px;z-index:99;position:absolute;">
pp</span>

        <div style="position:absolute;z-index:9;background:url(/images/minS/fonfortxt.png);width:750px;height:750px;margin:79px 125px;display:block;opacity:1 !important;filter:alpha(Opacity=100) !important;">fg</div>

      </div>

    </body>
  </html>

Gozar 12.08.2012 17:12

Цитата:

Сообщение от Brook (Сообщение 196956)
document.body.parentNode

Ответь на вопрос, - на что ты ссылаешься этой записью?
Зачем тебе здесь, parentNode?

Gozar 12.08.2012 17:16

Чтобы не ошибаться в таких мелочах можно делать так

el = document.getElementById('id');
el.parentNode.removeChild(el);

Brook 12.08.2012 17:24

Большое Вам спасибо за помощь!!


ТЕМА ЗАКРЫТА


Часовой пояс GMT +3, время: 10:01.