简体   繁体   English

根据另一个div中的点击显示/隐藏div

[英]show/hide a div based on click in another div

I have a chatbubble that when clicked, I want it to disappear and a chat window should come up. 我有一个chatbubble ,当单击该chatbubble时,我希望它消失并且应该出现一个聊天窗口。

The chat window is the wrapper div. 聊天窗口是wrapper div。 I set it display = 'none' in the html code below. 我在下面的html代码中将其设置为display = 'none' Then in the onclick of chatBubble I show the wrapper div using jQuery 然后在chatBubbleonclick ,我使用jQuery显示wrapper div

So initially I shouldn't see the chat window. 所以起初我不应该看到聊天窗口。 But I see it. 但是我看到了。 Also when I click on the chatbubble, I get error Uncaught TypeError: "#wrapper".show is not a function . 另外,当我单击聊天气泡时,我收到错误Uncaught TypeError: "#wrapper".show is not a function What am I missing? 我想念什么?

<div id = "chatBubble"  class="talk-bubble tri-right btm-right round">
     <div class="talktext">
        <p>Hi, can I help?</p>
     </div>
</div>

<div id="wrapper" display = 'none'>
    <div id="menu">
        <p class="welcome">Welcome<b></b></p>
        <p class="logout"><a id="exit" href="#">Exit</a></p>
        <div style="clear:both"></div>
    </div>

   <div id="chatbox"></div>

   <form name="message" action="">
      <input name="usermsg" type="text" id="usermsg" size="63" />
      <input name="submitmsg" type="submit"  id="submitmsg" value="Send" />
  </form>
</div>

Relevant portion of javascript javascript的相关部分

$(document).ready(function() {
  $("#chatBubble").click(function(){
    //console.log("clicked")
    ('#wrapper').show();
  })
});

Please suggest. 请提出建议。

You are setting the style property in the wrong way. 您以错误的方式设置了样式属性。 You have to set it through style attribute. 您必须通过样式属性进行设置。 show() is a jQuery function and you are missing that just before ('#wrapper').show(); show()是一个jQuery函数,您在('#wrapper').show();之前丢失了它('#wrapper').show(); which leads to the error. 导致错误。

Try the following: 请尝试以下操作:

 $(document).ready(function() { $("#chatBubble").click(function(){ //console.log("clicked") $('#wrapper').show(); }) }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id = "chatBubble" class="talk-bubble tri-right btm-right round"> <div class="talktext"> <p>Hi, can I help?</p> </div> </div> <div id="wrapper" style='display:none'> <div id="menu"> <p class="welcome">Welcome<b></b></p> <p class="logout"><a id="exit" href="#">Exit</a></p> <div style="clear:both"></div> </div> <div id="chatbox"></div> <form name="message" action=""> <input name="usermsg" type="text" id="usermsg" size="63" /> <input name="submitmsg" type="submit" id="submitmsg" value="Send" /> </form> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM