user605334
user605334

Reputation:

How to select child tag by 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 text to 1.

structure

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

Upvotes: 1

Views: 5683

Answers (1)

rahul
rahul

Reputation: 187030

You can use .text() method.

Something like

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

Upvotes: 2

Related Questions