New issue
Advanced search Search tips

Issue 680858 link

Starred by 3 users

Issue metadata

Status: WontFix
Owner: ----
Closed: Jan 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

document.getElementById returns null for elements inside html import

Reported by seandenn...@gmail.com, Jan 13 2017

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2979.0 Safari/537.36

Steps to reproduce the problem:
1. see [expected behavior] example

What is the expected behavior?
index.html
----------
<link rel="import" href="element.html">
<script>
    window.addEventListener(function() {
        console.log(document.getElementById('foo')); // null // should be <div id="foo">bar</div>
    });
</script>

element.html
------------
<div id="foo">bar</div>

What went wrong?
document query returns null for element inside html import

Did this work before? N/A 

Does this work in other browsers? N/A

Chrome version: 57.0.2979.0  Channel: dev
OS Version: 10.0
Flash Version: Shockwave Flash 24.0 r0
 

Comment 1 by woxxom@gmail.com, Jan 13 2017

The observed behavior is correct.

HTML import works differently. To access the content of an import, use the link element's .import property, which is defined only when certain conditions are met. See https://www.html5rocks.com/en/tutorials/webcomponents/imports/

Also, your addEventListener invocation is invalid: the first parameter should be the event name.
1) I meant to add the listener to the load event.

2) thanks for that article, I thought I saw it before, but I ended up needing document.currentScript.ownerDocument.

One thing to note though is that in my custom element script, in the global zone d.c.o was equal to the document, but from inside the class declaration for the element d.c was equal to null

Comment 3 by ajha@chromium.org, Jan 16 2017

Labels: Needs-Triage-M57

Comment 4 by ajha@chromium.org, Jan 20 2017

Cc: ajha@chromium.org
Components: Blink>HTML
Labels: Needs-Feedback
Thanks woxxom@ for your insight.
 
@reporter: Shall we close this if it is resolved as per C#1.
yes, this is fine to be closed.
Status: WontFix (was: Unconfirmed)
Thanks all!

Sign in to add a comment