且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用jQuery获取div中的下一个元素

更新时间:2021-08-12 06:48:18

next选择下一个元素:默认情况下,它不仅选择相同类型的元素.

next chooses the next element: by default it does not only select an element of the same type.

$('#test h2').next();      // selects the p
$('#test h2').next('p');   // selects the p
$('#test h2').next('h2');  // does not select the p

除非提供选择器,否则next 选择下一个兄弟元素.因此,您可以执行以下操作:

Unless you provide a selector, next will choose the next sibling element. You can therefore do this:

$('#test h2').text('Changed title').next().text('Changed text');