简体   繁体   English

通过id获取外部div,然后按类获取内部div

[英]get outer div by id, then get inner div by class

First I want to get the outer div by id, then the inner div by class (dynamically added by jquery mobile ui-collapsible content) and finally append a child text node to it. 首先,我希望通过id获取外部div,然后按类(由jquery mobile ui-collapsible内容动态添加)获取内部div,最后将子文本节点附加到其中。

<div id="aab" data-role="collapsible" data-content-theme="c">
     <h3>Heading</h3>
     <div class="ui-collapsible-content">
         <div id="coll">
             Collapsible Content
         </div>
     </div>
     </div>
     <p><button onclick='func()'>Button</button></p>    

   <script>
        function func() {
            var section = $("#aab > .ui-collapsible-content"); 
            section.appendChild(document.createTextNode("Hello world!"));
        }
    </script>

I also tried things out with document.getElementById but somehow it doesn't work.. Thanks in advance! 我也用document.getElementById尝试了一些东西但不知何故它不起作用..提前谢谢!

You have use jquery for selection so you should use it for adding child 您已经使用jquery进行选择,因此您应该使用它来添加子项

function func() {
  var section = $("#aab > .ui-collapsible-content"); 
  section.append("Hello world!");
}

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

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