How to get the selected elements ID

3,633 views
Skip to first unread message

dilantha

unread,
Aug 4, 2010, 7:58:43 AM8/4/10
to jsTree
Hi everyone,

Im very new to Jquery and jstree plugin. I want to get the id of the
selected node in js tree. i went through the documentation and saw
there is a function for that. but i couldn't figure out how to use it
since im new to jquery. When ever i click on a node i want to get the
id of that. Any help would be really appreciated. Thanks..

dilantha silva

unread,
Aug 5, 2010, 8:05:58 AM8/5/10
to jst...@googlegroups.com
Hi everyone,

Im pretty new to jstree plugin. can anyone please tell me how can i get the id of a tree node when i click on it. This is how i initiated the tree.


  $(function () {
        $("#tree").jstree({
            "json_data" : {
                "ajax" : {
                    "url" : "index.php?mod=logs&act=load_tree&stream=text",
                    //"url" : "_json_data.json",
                    "data" : function (n) {
                        return { id : n.attr ? n.attr("id") : "init" };
                    }
                }
            },
            "plugins" : [ "themes", "json_data",]

        });
    });

--

Any help would be really appreciated

Regards,

Dilantha Silva,

li3p

unread,
Aug 6, 2010, 3:56:25 AM8/6/10
to jsTree
Hi Dilantha,

The answer is in jsTree's documentation of UI plugin.
http://www.jstree.com/documentation/ui

check the get_selected() section.

dilantha silva

unread,
Aug 10, 2010, 1:04:48 PM8/10/10
to jst...@googlegroups.com
Hi Ivan,

Thanks a lot for your reply..It helped me to solve the issue..Thanks again..

On Tue, Aug 10, 2010 at 7:33 PM, vakata <ivan.b...@gmail.com> wrote:
Hi,

You could also use (plase it after/before the init code):

$("#tree").bind("select_node.jstree", function (e, data) {
 alert(data.rslt.obj.attr("id"));
});

Cheers,
Ivan
--
You received this message because you are subscribed to the Google Groups "jsTree" group.
To post to this group, send email to jst...@googlegroups.com.
To unsubscribe from this group, send email to jstree+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jstree?hl=en.




--
Regards,

Dilantha Silva,
http://twitter.com/dilanthasilva | http://www.linkedin.com/in/dilanthasilva|
https://launchpad.net/~dilantha

Balaji Panchatcharam

unread,
Feb 19, 2014, 9:59:23 AM2/19/14
to jst...@googlegroups.com
But i am getting the below error

Cannot read property 'obj' of undefined

when i have used the alert

 alert(data.rslt.obj.attr("id")); 


Ivan Bozhanov

unread,
Feb 19, 2014, 10:06:03 AM2/19/14
to jst...@googlegroups.com
That is normal - this is a topic from 4 years ago ... if you are using version 3 it is different - simply read the docs.

vakata

unread,
Aug 10, 2010, 10:03:56 AM8/10/10
to jsTree
Hi,

You could also use (plase it after/before the init code):

$("#tree").bind("select_node.jstree", function (e, data) {
alert(data.rslt.obj.attr("id"));
});

Cheers,
Ivan

On Aug 5, 3:05 pm, dilantha silva <dilantha.tyr...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages