user1542984
user1542984

Reputation:

how to deselect all element in jquery?

I want to deselect (remove selected element ).I am using jstree in my demo .So I read the plugin api . http://www.jstree.com/api/#/?f=deselect_all([supress_event]). But it not deleselect the selected item. I follow the these steps 1) Click the "b" node.then "b" node is selected. 2) Then press "deselect" button but it not deselect the items.

$('#deselect').click(function(){

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

})

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

Upvotes: 9

Views: 21868

Answers (3)

EspressoBeans
EspressoBeans

Reputation: 2015

I just learned that you can also use:

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

This will suppress the 'changed.jstree' event, which is what I needed for my page, and seems to be more along the lines of your original logic.

My working code excerpt verbatim:

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

Upvotes: 1

Ajay2707
Ajay2707

Reputation: 5798

What I use,

$('#deselect').click(function(){

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

})

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

by jquery change this

$('#deselect').click(function(){

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

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

else

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

})

Upvotes: 0

Manwal
Manwal

Reputation: 23816

Try this code:

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

Insted of

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

Here is Updated fiddle

Upvotes: 20

Related Questions