[ACCEPTED]-jquery find next element with class-next

Accepted answer
Score: 72

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

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

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

<span>no overwrite</span>

Next all looks at all siblings 1 that are next

Score: 4

Try this:

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

hope it helps. Sinan.


Score: 0

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

  .find("span.error:first").text("this button is disabled");

More Related questions