php - Addressing the Parent DOM in jQuery -


i have webpage generated same div according categories in database using simple query. in case there 2 categories. each div has button when clicked should change text of current divs titletext.

<body>  <div class="domparent" style="width: 100%; border: 1px solid #ff0000; margin: 10px; padding:10px;">     <div class="title">         <div class="titletext">category 1</div>         <button id="btn">id="btn" click me</button>     </div> </div>  <div class="domparent" style="width: 100%; border: 1px solid #ff0000; margin: 10px; padding:10px;">     <div class="title">         <div class="titletext">category 2</div>         <button id="btn">id="btn" click me</button>     </div> </div>   <script>      dp("#btn").click(function(){         dp(".titletext").html("this new title text");     });  </script>  </body> 

my problem in category 1 example, if click button change html both titletext when should change html titletext in category 1.

i have tried using incremental ids , sorts not answer. how change titletext in button's current domparent div?

this sample code written simplify problem code smaller. have left out mysql query , sorts because in end literally generated.

id property unique value, need change buttons id attribute class.

<button class="btn"> click me</button> 

and want access parent, should use parent() method of jquery. , need find children .titletext find method.

so can write code this, , check below example fiddle

$(this).parent().find(".titletext").text("this new title text"); 

example


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -