diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index a46502dcd03..85eac1dd055 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -5440,7 +5440,7 @@ void Document::element_id_changed(Badge, GC::Ref ele if (element->id().has_value()) insert_in_tree_order(m_potentially_named_elements, element); - else + else if (!element->name().has_value()) (void)m_potentially_named_elements.remove_first_matching([element](auto& e) { return e == element; }); auto new_id = element->id(); diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-01.txt b/Tests/LibWeb/Text/expected/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-01.txt new file mode 100644 index 00000000000..34a41e6f379 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-01.txt @@ -0,0 +1,12 @@ +Harness status: OK + +Found 7 tests + +7 Pass +Pass img elements that have a name and id attribute, should be accessible by both values. +Pass img elements that have a name and id attribute with same value. +Pass Dynamically removing the name attribute from img elements, should not be accessible. +Pass Dynamically removing the id attribute from img elements, should still be accessible by name value. +Pass Dynamically updating the name attribute from img elements, should be accessible by values. +Pass Dynamically updating the id attribute from img elements, should be accessible by values. +Pass img elements that is removed, should not be accessible. \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-01.html b/Tests/LibWeb/Text/input/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-01.html new file mode 100644 index 00000000000..2e8c1f2ce13 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-01.html @@ -0,0 +1,118 @@ + + +Named items: img id & name + + + + +
+
+ + + + + + + +
+