Question

Can't understand why this code changes color of DIV element to blue, but doesn't change color of a SPAN element. Any ideas?

<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  <script>
    $(document).ready(function(){
      $("#prev ~ div").css("color", "blue");
      $("#prev ~ span").css("color", "red");
    });
  </script>
</head>
<body>
  <span id="prev">span#prev</span>
  <div>div sibling</div>
  <span>span sibling</span>
</body>
</html>

Noticed what if I replace

<span id="prev">span#prev</span>

with

<p id="prev">span#prev</p>

both DIV and SPAN change text color.

Thanks!

Was it helpful?

Solution

Looks like you found a bug.

$("#prev ~ span:not(#prev)") works, as does $("#prev").siblings("span").

OTHER TIPS

This does indeed seem to be a bug. Report a bug to jQuery.

http://dev.jquery.com/report

There are a decent number of sibling selector bugs it seems.

Seems to be an error with JQuery. You should submit this bug to the team and let them fix it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top