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:
- <p class="thisone">text here</p>
- <p>blah blah</p>
- <p class="thisone">other text here</p>
- <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.