Avatar of Evan Cutler
Evan Cutler
Flag for United States of America asked on

JSTREE Check failure

I'm trying to fire this line:
$("#DivTree").jstree("check_node", $(this).text());

The $(this).text() works (I checked in firebug)...
but the Tree does not check the node...

Here's the code to the entire page:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Scratchpad.aspx.cs" Inherits="Scratchpad_Scratchpad" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    <%--CSS links--%>
    <link href="../Styles/ui-lightness/jquery-ui-1.8.14.custom.css" rel="stylesheet" type="text/css" />
    <link href="../Styles/grid/flexigrid.css" rel="stylesheet" type="text/css" />
    <link href="../Styles/textarea/jquery.cleditor.css" rel="stylesheet" type="text/css" />

    <%--Javascript links--%>
    <script src="../Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
    <script src="../Scripts/jstree/jquery.jstree.js" type="text/javascript"></script>
    <script src="../Scripts/ui/jquery-ui-1.8.14.custom.js" type="text/javascript"></script>
    <script src="../Scripts/Grid/flexigrid.js" type="text/javascript"></script>
    <script src="../Scripts/textarea/jquery.cleditor.js" type="text/javascript"></script>
    <script type='text/javascript' language='javascript'>

        $(document).ready(function () {

                "xml_data": {
                    "ajax": {
                        "url": "../data_services/Menu.ashx",
                        //"url": "FieldsOfStudyAdmin.aspx?callback=GetNodesJson",
                        "data": function (n) {
                            return { id: n.attr ? n.attr("id") : 0 };
                "checkbox": {
                    "two_state": true,
                    "override_ui": true
                "plugins": ["themes", "xml_data", "search", "dnd", "ui", "checkbox"]
            }).bind("check_node.jstree uncheck_node.jstree", function (e, data) {
                var checked_ids = new Array();
                $.jstree._focused().get_checked(-1, true).each(function () {
                    if (this.id) { checked_ids.push(this.id); }
                $("#Fields").val(checked_ids.join(", "));

                url: '../data_services/Ads.ashx',
                dataType: 'xml',
                method: 'GET',
                colModel: [
		            { display: 'Title', name: 'Title', width: 150, sortable: true, align: 'left', process: getID },
		            { display: 'Text', name: 'Text', width: 250, sortable: true, align: 'left', process: getID },
		            { display: 'Date', name: 'Date', width: 150, sortable: true, align: 'left', process: getID },
		            { display: 'Fields', name: 'Fields', width: 200, sortable: true, align: 'left', process: getID }
                searchitems: [
		            { display: 'Title', name: 'Title' },
		            { display: 'Text', name: 'Text', isdefault: true }
                sortname: "Title",
                sortorder: "asc",
                usepager: true,
                title: 'Countries',
                singleSelect: true,
                useRp: true,
                rp: 15,
                showTableToggleBtn: true,
                width: 750,
                height: 200
            $('#update').click(function () {
                var text = $('#Text').val();
                text = text.replace("\n", "");
                text = text.replace("\r", "");
            function getID(celDiv, id) {
                $(celDiv).click(function () {
                        type: "Post",
                        url: "../data_services/AdForm.asmx/GetAd",
                        dataType: "xml",
                        data: "PK=" + id,
                        success: function (xml) {
                            $(xml).find('formdata').each(function () {
                                var fieldlist = new Array();
                                $(this).find('fields').each(function () {
                                    $(this).find('field').each(function () {
                                        $("#DivTree").jstree("check_node", $(this).text());
                                $("#Fields").val(fieldlist.join(', '));

            $("#search").click(function () {
                $("#divTree").jstree("search", $("#fieldsearch").attr('value'));
<asp:Content ID="Content2" runat="server" contentplaceholderid="MainContent">
<table id="ads"></table>
<div id="output"></div>

<div id="form">
        PK:     <input id="pk" /><br />
        Title:  <input id="Title" value="insert Title Here" size="71" /><br />
        Fields: <input id="Fields" size="70"/><br />
        Text:   <textarea id="Text" rows="10" cols="80"></textarea>
            <input id="fieldsearch" type="text" /><div id="search"><a href="#">search for node</a></div><br />
            <div id="divTree"></div>
<a href="#" id="update" >Update Advertisement</a><a href="#" id="addnew">Add new Advertisement</a>

Open in new window


Avatar of undefined
Last Comment

8/22/2022 - Mon

>The $(this).text() works (I checked in firebug)...

what $(this).text() return ? the id of the checkbox? the class of the checkbox? or the text?

if this is the text, try this instead :
$("#DivTree").jstree("check_node", "li:contains('" + $(this).text() + "')");

Open in new window

Evan Cutler

the id is the text....

$(this).text() returns the text, which is also the id.

so, I thought it should work.

no you need to add # before :
$("#DivTree").jstree("check_node", "#" + $(this).text());

Open in new window

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Evan Cutler


Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Evan Cutler

I wish I could give you more points....

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.