I have this HTML structure
<div class="buttons">
<button data-icon="ui-icon-disk" class="save">Save1</button>
<button data-icon="ui-icon-check" class="ok">OK1</button>
<button data-icon="ui-icon-trash" class="delete">Delete1</button>
<button data-icon="ui-icon-close" class="close">Close1</button>
</div>
There are many blocks in the page like this one.
Some buttons come with click handlers functions (save and delete buttons).
What I want to do is: if someone click on an ok button, the corresponding save button click bound function should run.
My code:
$('.save').click(function(){
alert('save');
});
$('.ok').click(function(){
$('.save').click();
});
This is wrong, when I click on a ok button all save buttons fires... not only the one within the same buttons group.
Demo illustrating my problem.
Use $(this).siblings('.save').click()
to select only siblings of the clicked button instead of all matching buttons in the whole document.
Demo: http://jsfiddle.net/ThiefMaster/nMnm7/2/
Docs: http://api.jquery.com/siblings/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With