jQuery - .filter() _05

findet attr

by juErik

HTML

<div id="first"></div>
  <div id="second"></div>
  <div id="third"></div>
 
  <div id="fourth"></div>
  <div id="fifth"></div>
  <div id="sixth"></div>

CSS

div { width:60px; height:60px; margin:5px; float:left;
        border:3px white solid; }
  	</style>

JavaScript

/* Zuerst  werden alle div's blau gefärbt
    dann wird nach dem attr gesucht
    also könnte ich so manches mal auf eine Schleife verzichten!
*/

    $("div").css("background", "#b4b0da")
            .filter(function (index) {
                  return index == 1 || $(this).attr("id") == "fourth";
                })
            .css("border", "3px double red");