需要单击2次才能关闭div

时间:2018-04-29 04:55:54

标签: javascript html5 css3

我有一个div,我想在弹出时关闭它。我指的是this。只有更改是我给了span而不是按钮。现在我的问题是我需要在关闭符号上单击2次才能关闭div

我的代码

contactResault.html("
  <div id='hidediv' style='text-align:left'>
    <span id='close' onclick='this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode); return false;'>
      x
    </span>
    <h5 style='color:black;background-color:white!important;'>
      Thank you for Subscribing!
    </h5>
    <br/>
    <span style='color:black;background-color:white!important;'>
      Thank you for your interest in joining IEP|ONE, The Cognitive Companion for Children with Special Needs beta users group.
    </span>
    <br/>
    <br/>
    <span style='color:black;background-color:white!important;'> We will send you the link to download our Companion App from Apple and Google store as soon as it is available.
    </span>
    <br/>
    </br>
    <span style='color:black;background-color:white!important;'>Thank you!</span></br><span style='color:black;background-color:white!important;'>IEP|ONE Beta Users Team
    </span>
  </div>
");

的Javascript

document.getElementById('close').addEventListener('click', function(e) {
  e.preventDefault();
  this.parentNode.style.display = 'none';
}, false);  

和css

#close {
 float:right;
 display:inline-block;
 padding:2px 5px;
 background:#ccc;  
}

#close:hover {
 float:right;
 display:inline-block;
 padding:2px 5px;
 background:#ccc;
 color:#fff;
 cursor: pointer;
}

请帮助解决此问题。

0 个答案:

没有答案