开发者

How to select child tag by closest tag in jQuery

开发者 https://www.devze.com 2023-02-09 04:29 出处:网络
i have select the element in jQuery who used currently clicked. i try parent but that\'s not worked so i try the closest tag in jQuery

i have select the element in jQuery who used currently clicked. i try parent but that's not worked so i try the closest tag in jQuery

$(this).closest('.posts').children('.cbl h1').html('1')

i try this and it's work fine to selection means i select the tag .cbl h1 successfully. now tell me how i can change the t开发者_开发问答ext to 1.

structure

   <div class='posts'>
    <div class='cbl'>
    </div>
<div><div>$(this) element is here</div></div>
    </div>


You can use .text() method.

Something like

$(this).closest('.posts').children('.cbl h1').text('1');
0

精彩评论

暂无评论...
验证码 换一张
取 消