change the closest class to my clicked button

change the closest class to my clicked button

Hi all

I have a class applied to many different elements throughout my site.  On one page I have a button which when clicked needs to update one instance of this class (the closest instance to the button) in the DOM but I cannot get this to work. A loose example of my HTML is below:

  1. <p class="thisone">text here</p>
  2. <p>blah blah</p>
  3. <p class="thisone">other text here</p>
  4. <input type="button" id="mybtn1">


What I need to do is ensure that when the #mybtn1 button is clicked, only the closest instance of the "thisone" class to the button changes its text.

How can I achieve this with jquery?


Thank you.