summaryrefslogtreecommitdiff
path: root/Libraries/LibHTML
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries/LibHTML')
-rw-r--r--Libraries/LibHTML/HtmlView.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/Libraries/LibHTML/HtmlView.cpp b/Libraries/LibHTML/HtmlView.cpp
index 66eb4462d7..b467290cdf 100644
--- a/Libraries/LibHTML/HtmlView.cpp
+++ b/Libraries/LibHTML/HtmlView.cpp
@@ -319,17 +319,20 @@ void HtmlView::scroll_to_anchor(const StringView& name)
if (!document())
return;
- HTMLAnchorElement* element = nullptr;
- document()->for_each_in_subtree([&](auto& node) {
- if (is<HTMLAnchorElement>(node)) {
- auto& anchor_element = to<HTMLAnchorElement>(node);
- if (anchor_element.name() == name) {
- element = &anchor_element;
- return IterationDecision::Break;
+ const HTMLAnchorElement* element = nullptr;
+ if (auto* candidate = document()->get_element_by_id(name)) {
+ if (is<HTMLAnchorElement>(*candidate))
+ element = to<HTMLAnchorElement>(candidate);
+ }
+ if (!element) {
+ auto candidates = document()->get_elements_by_name(name);
+ for (auto* candidate : candidates) {
+ if (is<HTMLAnchorElement>(*candidate)) {
+ element = to<HTMLAnchorElement>(candidate);
+ break;
}
}
- return IterationDecision::Continue;
- });
+ }
if (!element) {
dbg() << "HtmlView::scroll_to_anchor(): Anchor not found: '" << name << "'";