How can I select a clicked item AND a subsequent item - Jquery
how can I select the item just clicked AND a subsequent item, using Jquery... At the moment whenever I try to use the 'this' attribute along side another selector, it stops working...
HTML
<a href="#" class="refLink">9</a>
<span class="refPanelFloating">Blah blah blah</span>
T开发者_JAVA技巧ried Jquery
$('a.refLink').click(function () {
$(this,'span.refPanelFloating').wrapAll('<span class="refWrap" />');
});
Desired result
<span class="refWrap">
<a href="#" class="refLink">9</a>
<span class="refPanelFloating">Blah blah blah</span>
</span>
At the moment I can only get it to work by selecting the initial 'a.refLink' tag... but on the final page there will be lots of them...
Thanks
Try this:
$('a.refLink').click(function () {
$(this).next().andSelf().wrapAll('<span class="refWrap" />');
});
See http://jsfiddle.net/alnitak/M8weS/
The key is the .andSelf()
function which merges the result of the previous two chained calls into one list.
精彩评论