开发者

To add a different color using jquery and css

<div id="autoSuggestedPlaces">

      <div>
           <div>

          </div>
      </div>

      <div>
           &l开发者_JAVA百科t;div >

          </div>
      </div>

      <div>
           <div>

          </div>
      </div>


</div>

my html markup is lookes like this i want to add, i want to add even div have diffrent bacground color and odd div have diffrent color, I tried this but using div.even and div.odd but its not working.


Try this

$("div#autoSuggestedPlaces div div:even").css("background-color", "#bbbbff");
$("div#autoSuggestedPlaces div div:odd").css("background-color", "#ffffff");


the code is like :

 $("div:odd").css("background-color", "#F4F4F8");
  $("div:even").css("background-color", "#EFF1F1");

and Using the same ID twice in the same document is not valid HTML. Fix your HTML.


Try using :even and :odd

div.even will select all div elements with class name even.

Also as pointed out by @Haim never use same id for multiple elements.

.first
{
    background-color: yourfirstcolor;
}


.second
{
    background-color: yoursecondcolor;
}

$("#autoSuggestedPlaces div:even").addClass("first");
$("#autoSuggestedPlaces div:odd").addClass("second");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜