diff --git a/Definitions/jquery-1.8.d.ts b/Definitions/jquery-1.8.d.ts index 898be4799..720fffdc4 100644 --- a/Definitions/jquery-1.8.d.ts +++ b/Definitions/jquery-1.8.d.ts @@ -614,7 +614,7 @@ interface JQuery { /************* MISCELLANEOUS **************/ - each(func: (index: any, elem: Element) => JQuery); + each(func: (index: any, elem: Element) => any); get(index?: number): any; diff --git a/Tests/jquery-tests.ts b/Tests/jquery-tests.ts index 9e3ecf064..4fd5186eb 100644 --- a/Tests/jquery-tests.ts +++ b/Tests/jquery-tests.ts @@ -465,4 +465,34 @@ function test_attributeSelectors() { $('input[value="Hot Fuzz"]').next().text(" Hot Fuzz"); $('input[name!="newsletter"]').next().append('; not newsletter'); $('input[name^="news"]').val('news here!'); +} + +function test_each() { + $('li').each(function (index) { + alert(index + ': ' + $(this).text()); + }); + $(document.body).click(function () { + $("div").each(function (i) { + if (this.style.color != "blue") { + this.style.color = "blue"; + } else { + this.style.color = ""; + } + }); + }); + $("span").click(function () { + $("li").each(function () { + $(this).toggleClass("example"); + }); + }); + $("button").click(function () { + $("div").each(function (index, domEle) { + // domEle == this + $(domEle).css("backgroundColor", "yellow"); + if ($(this).is("#stop")) { + $("span").text("Stopped at div index #" + index); + return false; + } + }); + }); } \ No newline at end of file