How to deselect all elements in jquery?

I want to deselect (delete selected item). I am using jstree in my demo. So I'm reading the api plugin. http://www.jstree.com/api/#/?f=deselect_all ([supress_event]) . But this does not cancel the selected item. I follow these steps 1) Press the "b" node. Then select the "b" node. 2) Then click the β€œdeselect” button, but do not deselect the items.

$('#deselect').click(function(){ alert('--') $('#tree').deselect_all(true) }) 

http://jsfiddle.net/fuu94/150/

+6
source share
3 answers

Try this code:

 $('#tree').jstree("deselect_all"); 

Established

 $('#tree').deselect_all(true) 

Here is the updated fiddle

+14
source

I just found out that you can also use:

$('#tree').jstree("deselect_all", true);

This will suppress the "changed.jstree" event, which I need for my page, and seems to be more in line with your original logic.

An excerpt from my working code is verbatim:

 function DeselectTree() { $('[id ^= "forms-foldertree-"]').each(function () { $(this).jstree('deselect_all', true); }); } 
+1
source

What i use

$ ('# Cancel'). Press (function () {

$ ('# tree'). attr ("checked", false);

})

or you can add custom attributes and give stylesheet / class for select / deselect

using jquery change this value

$ ('# Cancel'). Press (function () {

if ($ ('# tree'). attr ("customattr") == "select")

  $('#tree').attr("customattr", "unselect"); 

yet

 $('#tree').attr("customattr", "select"); 

})

0
source

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


All Articles