I have the following markup:
<button class="button" type="button"><span>Edit</span></button>
I want to have a click event on .button that changes the value of the next span.
So I have this as a test:
$('.button').click(function(){
$(this).next('span').val();
})
This returns ‘undefined’ however. How can I select the span?
Thank you!
you need to fix two things. First
next()applies to sibling elements. yourspanis inside yourbutton. So change that to children. Next to get the value inside aspanelement you’ll need to use .html()EDITED:
Here is a jsFiddle