How to insert an element into a selectable control

Is there a "clean" way to insert an element into a jQuery UI Selectable control?

Let's say I have the following choice:

<div id="selectable"> <div>Item 1</div> <div>Item 2</div> <div>Item 3</div> </div> 

I could manually insert a line, for example:

 $('<div>Item 4</div>').addClass('ui-selectee').appendTo($('#selectable')); 

While it visually looks right, are there any events that I need to enable? Is this a clean way to insert an item, or is there a better way?

+4
source share
2 answers

There is no api for this. Therefore, I believe that your encoding is correct. You can also try calling .selectable( "refresh") after adding.

+1
source

According to the API, you can also simply use the autoRefresh parameter (enabled by default) to expand the list of selectable elements when adding elements to the DOM element.

If you have a huge list of items, it is recommended that you set autoRefresh to false and call the update method manually.

+1
source

Source: https://habr.com/ru/post/1346152/


All Articles