diff --git a/Userland/Libraries/LibWeb/Layout/RadioButton.cpp b/Userland/Libraries/LibWeb/Layout/RadioButton.cpp index 5f3de1ff5f..9521f2f705 100644 --- a/Userland/Libraries/LibWeb/Layout/RadioButton.cpp +++ b/Userland/Libraries/LibWeb/Layout/RadioButton.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -105,20 +106,12 @@ void RadioButton::set_checked_within_group() return; dom_node().set_checked(true); - - if (!parent()) - return; - String name = dom_node().name(); - parent()->for_each_child_of_type([&](auto& child) { - if (&child == this) - return; - if (!child.dom_node().checked()) - return; - - if (child.dom_node().name() == name) - child.dom_node().set_checked(false); + document().for_each_in_subtree_of_type([&](auto& element) { + if (element.checked() && (element.layout_node() != this) && (element.name() == name)) + element.set_checked(false); + return IterationDecision::Continue; }); }