Search from google for the jquery on how to get sibling
You cannot write:
next("a"), because next() only tries to match the very next element. It will hit the<br>element and match nothing.closest("a"), because closest() walks up the ancestor chain, starting with the element itself, and therefore will miss the<a>elements.
You can write:
next().next(), as Arend suggests. That's probably the fastest solution, but it makes the<br>elements mandatory.nextUntil("a").last().next(), which only iterates over the next siblings until it finds a link, then returns the immediate next sibling of the last element matched. It might be faster thannextAll(), again, depending on your markup.Ref: http://stackoverflow.com/questions/6237673/cleanest-way-to-get-a-sibling-in-jquery
沒有留言:
張貼留言