Fix jQuery each definition

This commit is contained in:
Boris Yankov
2012-11-05 11:07:13 +02:00
parent c3db5ea91c
commit 0bd52c6c32
2 changed files with 31 additions and 1 deletions
+1 -1
View File
@@ -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;
+30
View File
@@ -465,4 +465,34 @@ function test_attributeSelectors() {
$('input[value="Hot Fuzz"]').next().text(" Hot Fuzz");
$('input[name!="newsletter"]').next().append('<b>; not newsletter</b>');
$('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;
}
});
});
}