How to dynamically create Polymer custom element after setting all attributes?

Asked By: Anonymous

The problem is when I try to create custom element this way

var el= document.createElement('my-el');
el.setAttribute('tag-model', "[[myBinding]]");

it creates element without its attributes. How to construct custom element with all its attributes and then append to HTML to initilize them?

Thank you!


Solution

Answered By: Anonymous

See this

It basically says to do it like that:

var dynamicEl = document.createElement("my-element");
dynamicEl.setAttribute("id", "my-element-id");
dynamicEl.setAttribute("greeting", "Hello, Good Morning.");
document.body.appendChild(dynamicEl);

However, if you want to change properties directly, it wont work with setAttribute. You have to do it like that:

var dynamicEl = document.createElement("my-element");
dynamicEl.greeting = 'Waaazaaaa???';
document.body.appendChild(dynamicEl); 
techinplanet staff

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno