Adding a class programatically


I’m doing this:

absoluteLayout.className = "dropCategory";
const lbl = new Label();
lbl.text = `drop${i}`;

The layout gets added with the label. The className gets added, but the styles are not picked up. Isn’t this the proper way to add class to a programmatically added element?

Here is what the added element looks like in the debugger:

<AbsoluteLayout effectiveTop="0" top="0" className="dropCategory">
    <Label text="drop0"></Label>

If I create the element manually in the template and use class instead of className I see the styles applied to the element. It only does’t apply styles when I do this in the code behind.


Where you have the style definition for dropCategory, in the page level CSS file or in app level CSS file?


Ah, I had it in the component level css. If I move it up the tree, I see it picks it up. Thanks