diff --git a/pkgs/html/CHANGELOG.md b/pkgs/html/CHANGELOG.md
index eaa1f8c00a..aa68aed2d5 100644
--- a/pkgs/html/CHANGELOG.md
+++ b/pkgs/html/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.15.6-wip
+
+- Fixed a TypeError in nth-child with non numeric value (e.g. `nth-child(even)`)
+
## 0.15.5+1
- Support "ambiguous ampersand" in attribute values.
diff --git a/pkgs/html/lib/src/query_selector.dart b/pkgs/html/lib/src/query_selector.dart
index b57b81145a..0c48db24ee 100644
--- a/pkgs/html/lib/src/query_selector.dart
+++ b/pkgs/html/lib/src/query_selector.dart
@@ -218,10 +218,17 @@ class SelectorEvaluator extends Visitor {
final exprs = node.expression.expressions;
if (exprs.length == 1 && exprs[0] is LiteralTerm) {
final literal = exprs[0] as LiteralTerm;
+
+ if (literal.value is! num) {
+ // non numeric values (e.g. `nth-child(even)`) are not supported
+ return false;
+ }
+
+ final numericLiteral = literal.value as num;
final parent = _element!.parentNode;
return parent != null &&
- (literal.value as num) > 0 &&
- parent.nodes.indexOf(_element) == literal.value;
+ numericLiteral > 0 &&
+ parent.nodes.indexOf(_element) == numericLiteral;
}
break;
diff --git a/pkgs/html/pubspec.yaml b/pkgs/html/pubspec.yaml
index 7508588ad7..cdc502f0a7 100644
--- a/pkgs/html/pubspec.yaml
+++ b/pkgs/html/pubspec.yaml
@@ -1,5 +1,5 @@
name: html
-version: 0.15.5+1
+version: 0.15.6-wip
description: APIs for parsing and manipulating HTML content outside the browser.
repository: https://github.com/dart-lang/tools/tree/main/pkgs/html
issue_tracker: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Ahtml