jQuery prevUntil() include start selector and end selector

只愿长相守 提交于 2019-12-21 01:48:10

问题


I would like to select the start and end selector for the prevUntil() or nextUntil() jQuery selector methods. If I implement these methods now, it grabs everything between the two selectors given.

i.e. $('p').prevUntil('h1') will not include the p and h1 element, only those between them. How could I also select the p and h1 elements as well as though between?


回答1:


Take a look at the .addBack method to add the results of the previous selector to the current matches. Combining that with the .prev method seems to do the trick:

$('p').prevUntil('h1').addBack().prev('h1').addBack();


来源:https://stackoverflow.com/questions/2770588/jquery-prevuntil-include-start-selector-and-end-selector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!