Javascript 默认情况下隐藏动态生成的内容

Javascript 默认情况下隐藏动态生成的内容,javascript,jquery,Javascript,Jquery,在我的javascript文件中,我有以下模板字符串,其中包含默认情况下要隐藏的带有id=“update quote form”的表单: $("#quoteTarget").append( `<h3>${index.phrase}</h3> <h4>${index.author}</h4> <div class="childshow">

在我的javascript文件中,我有以下模板字符串,其中包含默认情况下要隐藏的带有
id=“update quote form”
表单:

$("#quoteTarget").append(
          `<h3>${index.phrase}</h3>
              <h4>${index.author}</h4>
            <div class="childshow">
                <a href="javascript:void(0)" class="delete-quote">
                  <span class="glyphicon glyphicon-trash" value="${index._id}">
                </a>

                <a href="javascript:void(0)" class="update-quote">
                  <span class="glyphicon glyphicon-pencil" value="${index._id}">
                </a>

                <div class='childshow'>
                  <form id="update-quote-form">
                    <div class="form-group">
                      <input type="text" name="phrase" class="form-control" placeholder="${index.phrase}">
                    </div>
                    <div class="form-group">
                      <input type="text" name="author" class="form-control" placeholder="${index.author}">
                    </div>
                    <div class="form-group">
                      <input class="temp" type="submit" value="submit change" name="${index._id}">
                    </div>
                  </form>
                </div>
            </div>
              <hr>`
我尝试在css中将其设置为
display:none
,但我相信单击处理程序不会注意到它,因为它没有加载


有办法解决这个问题吗?

设置css
显示应该可以很好地工作(不过我对代码做了一些修改)——

var索引={作者:“测试”,短语:“测试短语”,_id:1}
$(“#quoteTarget”)。追加(
`${index.phrase}
${index.author}
点击我

`); //$('#quoteTarget')。悬停(函数(){ $(“.childshow header”)。在(“单击”上,函数(e){ //控制台日志(“hi”); //e.停止传播(); $(this).next(“.childshow content”).toggle(); }); //});
.childshow标题{
宽度:100%;
高度:20px;
背景颜色:灰色;
}
.儿童节目内容{
显示:无;
}
.


将HTML代码也添加到问题中。其中是
quoteTarget
元素和表单
updatequote表单
谢谢,这很有效。但是,由于某些原因,将单击目标类“childshow header”添加到我的glyphicon不起作用。尝试用按钮替换,但仍然无法切换。不知道为什么会发生这种情况。@DanT-如果你能为这件事创建一个plunker,我可以帮你。
$('#quoteTarget').hover(function() {
  $(".childshow").on("click",function (e) {
      console.log("hi");
      e.stopPropagation();
      $(this).children('.childshow').toggle();
  });