LibHTML: <a href="#foo"> should prefer any element type with id=foo

It turns out that other engines also prefer <h1 id=x> over <a name=x>.
So we can just use get_element_by_id() directly without worrying about
the type of element we find.
This commit is contained in:
Andreas Kling 2019-10-21 12:12:23 +02:00
parent 8e710b16de
commit 04b94a7695
Notes: sideshowbarker 2024-07-19 11:36:00 +09:00

View file

@ -319,11 +319,7 @@ void HtmlView::scroll_to_anchor(const StringView& name)
if (!document())
return;
const HTMLAnchorElement* element = nullptr;
if (auto* candidate = document()->get_element_by_id(name)) {
if (is<HTMLAnchorElement>(*candidate))
element = to<HTMLAnchorElement>(candidate);
}
auto* element = document()->get_element_by_id(name);
if (!element) {
auto candidates = document()->get_elements_by_name(name);
for (auto* candidate : candidates) {