Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Dynamically created/destroyed elements.

A sheet worker does not have access to jQuery's $ identifier. Is it possible to dynamically create/destroy objects in a character sheet? What i'm trying to do is create roll buttons inside a container when a repeating section is changed, like this: on("change:repeating_agility change:repeating_will change:repeating_otherattribute", function(eventInfo) { let out = ""; let changedgroup = eventInfo.sourceAttribute.split("_")[1]; getSectionIDs("repeating_"+changedgroup,function(idarray) { idarray = idarray.map(function(x) { return "repeating_"+changedgroup+x; }); let idarray2 = [...idarray]; idarray = idarray.map(function(x) { return x+"_spec_name"; }); idarray2 = idarray2.map(function(x) { return x+"_spec_rating"; }); getAttrs([...idarray,...idarray2], function(values) { idarray2.forEach(function(id) { out += "<button class='sheet-spec-button' type='roll' value='&{template:imaroll} {{[[(@{"+changedgroup+"_rating}+"+values["repeating_"+changedgroup+id+"_spec_rating"]+")d6dl"+values["repeating_"+changedgroup+id+"_spec_rating"]+"]]}}'>"+values["repeating_"+changedgroup+id+"_spec_name"]+": "+values["repeating_"+changedgroup+id+"_spec_rating"]+"B</button>"; }); $("#spanout_"+changedgroup).html(out); }); }); }); Which obviously doesn't work. The repeating section is designed to be hidden with a toggle, so as to not clutter the character sheet.
1556853535
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You can create repeating items in a repeating section, and you can conditionally display something based on a value set by the sheetworkers. You cannot create html entities from scratch. Is the button you want to create inside or outside a repeating item?
The idea was to place it outside the repeating section. Currently the layout of the area is that it's two rows of a table per attribute - the first row is the 'display' row, containing 3 cells (for the attribute's rating, base rollbutton, and the container where i'm trying to put these mini-buttons), and the second is a colspan-3'd single cell that contains the repeating section (so as to not try and intersect a table and a repeatable section because... yeahhhh...) But if we can't create elements from scratch, that would limit that idea. However, looking at the system document again, spec_name is a closed set for each attribute, which means i could do it via conditionals and just... hide (or more accurately, not show) all the buttons that don't appear in the repeating list. Can a sheet worker change the label of an existing button? (Immediate self-answer: If you put a span inside the button and name it as an attribute, the system will write into it by writing the attribute?)