简体   繁体   中英

Replace the text using jquery closest

The thing I have tried so far is

     <h3>This is what I want to display inside "ppname"</h3><a class="" href="javascript:" code="displayed">HO</a>
 <h3>Just for test</h3>
<div class="pp" style="display:none;">Not
    <div class="ppname"></div>
    <div class="ppcode"></div>
</div>

The Jquery

$('a[code]').click(function () {
    $('.ppcode').html($(this).attr('code'));
    $('.ppname').html($(this).closest("h3").html());
    $('.pp').show();
});
$('span.close').click(function () {
   $('.pp').hide();  
  }); 

The text in attribute code is displaying inside the div with class ppcode but the text in h3 is not displaying inside div with class ppname. Thanks

使用prev而不是closest的语句来显示This is what I want to display inside "ppname"ppnameThis is what I want to display inside "ppname"的内容:

$('.ppname').html($(this).prev().html());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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