Selector trouble
Selector trouble
Hopefully this is an easy one, but I'm having trouble getting a selector working. Probably best just to give you some example code:
HTML
- <input type='button' class='test' value='Button Name'>
- <div>
- <a href='' class='buttonLink' />Click me</a>
- </div>
Jquery
- $(.buttonLink).click(function() { $(this).closest(':button.test').addClass('testclass'); });
Form that code I would expect the class of 'testclass' to be applied to the button after the link is clicked, but It doesn't seem to work.
This is a somewhat contrived example. In my real application I have a form with several collapsable/expandable sections. If the fields in those form sections have values when the page loads, the section needs to be expanded, and the expand/collapse button needs to have a class of 'expaned' applied to it, if not it needs to be hidden. I can check the form fields and show the div if needed without any problem, but I can't seem to figure out how to work out the selector so I can add the class to the button.