Brian Kalski
Brian Kalski

Reputation: 957

Setting the class of a dynamically created paper-button doesn't work

I have the following code that creates a paper-button dynamically. It works well but I can't figure out how to set the class.

var button = document.createElement('paper-button');
button.raised = true;
Polymer.dom(button).textContent = 'dynamic';
Polymer.dom(button).innerHTML = "New Button Text";    
$(".notificationCollection").append(button);

This does not work:

Polymer.dom(button).class = "notificationBarButton";

I couldn't find anything in the documentation. Thanks.

Upvotes: 0

Views: 50

Answers (2)

Kuba Šimonovský
Kuba Šimonovský

Reputation: 2043

additionaly, you can use

Polymer.dom(button).className = "notificationBarButton";

or even

Polymer.dom(button).classList.add("notificationBarButton");

classList has more functions .remove or .toggle.

documentation to classList: https://developer.mozilla.org/en-US/docs/Web/API/Element/classList

Upvotes: 2

Brian Kalski
Brian Kalski

Reputation: 957

I stumbled upon the answer.

button.setAttribute("class", "notificationBarButton");

Upvotes: 0

Related Questions