jquery find next element with class

泪湿孤枕 提交于 2019-12-03 10:22:02
PetersenDidIt

The problem is that your using the next traversing function rather than nextAll

$("button[disabled]").nextAll(".error").text("this button is disabled");

When you use next its just looking at the "next" element which is

<span>no overwrite</span>

Next all looks at all siblings that are next

Try this:

$("button[disabled=disabled]").parent().find("span.error").text("this button is disabled");

hope it helps. Sinan.

next() won't work in this case because it has to be a sibling for that to work. In this case you need:

$("button[disabled]").parent().nextAll()
  .find("span.error:first").text("this button is disabled");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!