Jquery 获取隐藏文本并将其放入div标记中

Jquery 获取隐藏文本并将其放入div标记中,jquery,Jquery,单击锚定标记时,“anotherDiv”可见 使用jQuery,我希望能够在锚标记的每个li onClick中获取描述,并将其插入到锚标记的“anotherDiv”区域中,该区域在锚标记的每个li onClick中也是可见的。说明文字最初设置为显示无 <style> .desc{ display:none; } #anotherDiv{ display: none; } </style> <

单击锚定标记时,“anotherDiv”可见

使用jQuery,我希望能够在锚标记的每个li onClick中获取描述,并将其插入到锚标记的“anotherDiv”区域中,该区域在锚标记的每个li onClick中也是可见的。说明文字最初设置为显示无

<style>
    .desc{
     display:none;
    }

    #anotherDiv{
       display: none;
    }

</style>

        <li style="overflow: hidden; float: none; width: 158px; height: 125px;">
                    <a onClick="return addPlayer(952541791001, 661361792001, 600, 320)" id="no8" class="video-pop">
                        <img width="132" height="75" alt="" src="image.jpg">
                    </a>
                    <div class="label">The label goes here......</div>
                    <div class="desc">The description goes here.....</div>
                </li>
      <li style="overflow: hidden; float: none; width: 158px; height: 125px;">
                    <a onClick="return addPlayer(952541791001, 661361792001, 600, 320)" id="no10" class="video-pop">
                        <img width="132" height="75" alt="" src="image.jpg">
                    </a>
                    <div class="label">The label goes here......</div>
                    <div class="desc">The description goes here.....</div>
                </li>
    -------------------------------------------------------------
    <div id="anotherDiv"></div>

.描述{
显示:无;
}
#另一个{
显示:无;
}
  • 标签在这里。。。。。。 描述如下。。。。。
  • 标签在这里。。。。。。 描述如下。。。。。
  • -------------------------------------------------------------
    单击列表项时,获取子描述。然后将其html插入另一个div中

    $('li').click( function() {
         $('#anotherDiv').html($(this).children('.desc').html());
    });
    
    //a more readable format to help you understand
    $('li').click( function() {
         //$this is the clicked list item. We search its children for class `desc` and get contents
         var desc = $(this).children('.desc').html();
         //set anotherDiv's contents
         $('#anotherDiv').html(desc);
    });
    
    试试这个:


    当我试图显示隐藏元素时,它返回空。因此,我应该能够首先使文本可见,然后插入到另一个div中。@web\u dev-这是因为另一个div是隐藏的。您可以使用
    show
    或使用
    fadeIn
    slideDown
    来显示它。请确保在回答中张贴您的代码。这样,未来的访问者可以从您的知识中受益。
    $('a').bind('click.myClick', function() {
        var that = $(this);
      $('#anotherDiv').text(that.parent().find('.desc').text()).show();
    
    });