I’ve got two separate arrays which look like this
12-Jan-12 (remove), 14-Mar-12 (remove)
£139, £187
When someone click the remove button in array I need it to remove the the one from the second array in the same position
So if i clicked remove on the 12-Jan-12 then i want it to remove £139 from the second array
Here’s some code I have already to remove one from the first array
$('.delete-date').live('click', function() {
$(this).closest('.myDate').remove();
});
Here’s my HTML
<span class="dates">
<span class="myDate">
12-jan-12
<span class="delete-date" title="remove this tag" />
</span>,
<span class="myDate">
14-mar-12
<span class="delete-date" title="remove this tag" />
</span>,
</span>
<span class="costs">
<span class="myCost">
£139
</span>,
<span class="myCost">
£187
</span>,
</span>
Any ideas?
Thanks in advance
With jQuery you can get the index of an sibling with the
.index()method and use the.eq()method to select an element based on it’s index. So:NB: Instead of
.live(), you should consider usingdelegate()(or.on()with jQuery 1.7), as it’s much more efficient.