JavaScript Webcomponent / custom-element instance stops parsing on first <script> tag web component custom element,web component custom element example,@webcomponents/

Using Google Chrome (v42) and the native webcomponents support, I am trying to use a custom element, where the custom element content sometimes contains inlined javascript tags. However, the parser seems to stop parsing the element content whenever it encounters the first <script> tag. What am I doing wrong? How can I make sure my custom element knows it's entire content when the initializer (e.g. createdCallback) runs?

Simplified example:

<html>
  <body>
    <script>
      document.registerElement("element-count", {
        prototype: Object.create(HTMLElement.prototype, {
          createdCallback: {
            value: function(){
              this.appendChild(document.createTextNode(this.children.length));
            }
          }
        })
      })
    </script>

    <element-count>
      <div>alpha</div>
      <script></script><!-- this is here just to show that the parser stops -->
      <div>beta</div>
    </element-count>
  </body>
</html>

Expected result:

alpha
beta
3

Actual result:

alpha
2
beta

The custom element's createdCallback runs as soon as the parser encounters the <script> element.

I don't have much control over the document fragment within the custom element (inside of the <element-count>). The real-world version of the custom component tries to wrap arbitrary DOM fragments into richly decorated boxes and do some other stuff.

Answer:1

This is probably a trivial question, but I'm trying to look for the most efficient way to do this. I am given a string in this format "20130914" from a servlet and I need to create a javascript date ...

This is probably a trivial question, but I'm trying to look for the most efficient way to do this. I am given a string in this format "20130914" from a servlet and I need to create a javascript date ...

  1. javascript convert yyyymmdd to date
  2. javascript convert yyyymmdd to yyyy-mm-dd
  3. javascript convert yyyymmdd string to date
  4. javascript convert yyyymmdd
  5. js convert yyyymmdd to date
  6. convert yyyymmdd to date in javascript
  7. convert yyyymmdd to date js
  8. convert yyyymmdd to date javascript

With JavaScript or CoffeeScript, is there an easy way to test for the following: if (locals.messages.text === "somestring") { ... } Now this needs three things to be true: locals needs to exist, ...

With JavaScript or CoffeeScript, is there an easy way to test for the following: if (locals.messages.text === "somestring") { ... } Now this needs three things to be true: locals needs to exist, ...

I have a webpage aligned properly when viewed fullscreen in a browser, but when the same is resized things go horribly mis-aligned. Here's the html. <html> <head> <style type='text/css'...

I have a webpage aligned properly when viewed fullscreen in a browser, but when the same is resized things go horribly mis-aligned. Here's the html. <html> <head> <style type='text/css'...

function Class () { var self = this; this.hi = true; // this { hi: true }, self { hi: true } self.hi = false; // this { hi: false }, self { hi: false } } Why doesn't self behave like a normal var?

function Class () { var self = this; this.hi = true; // this { hi: true }, self { hi: true } self.hi = false; // this { hi: false }, self { hi: false } } Why doesn't self behave like a normal var?