jQuery each
- <ul id='a'>
- <li>aa</li>
- <li>dd</li>
- <li>dda</li>
- </ul>
- $("ul li ").each(function(){
- //alert($(this).text());
- })
- <button>Change colors</button>
- <span></span>
- <div></div>
- <div></div>
- <div></div>
- <div></div>
- <div id="stop">Stop here</div>
- <div></div>
- <div></div>
- <div></div>
- $("button").click(function () {
- $("div").each(function (index, domEle) {
- // domEle == this
- alert(index);
- $(domEle).css("backgroundColor", "yellow");
- if ($(this).is("#stop")) {
- $("span").text("Stopped at div index #" + index);
- return false;
- }
- });
- });
浙公网安备 33010602011771号