Is it possible to dynamically insert an element into an HTML page using Dukescript

104 Views Asked by At

I would like to dynamically add/remove elements from a DukeScript page - in response to user actions.

Is this possible?

1

There are 1 best solutions below

0
On BEST ANSWER

Yes it's possible. There are different ways to achieve that. DukeScript uses knockout bindings in the html.

If you want to add remove an element from a dom you can embedd it in a conditional block:

http://knockoutjs.com/documentation/if-binding.html

Now depending on a property in your model the content of this block will be added to the dom. If for example your user ticks a checkbox, a boolean property of your model will be true, then the condition will apply and your dom elements will be added.

If you want for example to add new elements to a list, you can use the foreach binding:

http://knockoutjs.com/documentation/foreach-binding.html

You can bind it to an array type property of your model. Then for each of the elements the dom elements enclosed in the foreach block will be added. The data of this element can be bound to the properties of the list element.

and there are other ways... It really depends on what exactly you want. If you give an example of what you want to achieve it would help identify the best way of doing it.