obteniendo un error al navegar por el árbol jquery

While fetching Node value of a tree, when I am clicking on submenu, though its getting placed inside input field txt, there is am error.... The error says

Message: 'target.childNodes.0.nodeValue' is null or not an object
Línea: 9
Char: 3
Código: 0

Any help??? thanks..

HTML

<ul id="browser" class="filetree">
    <li><span class="folder">Souvik_Workspace</span>
        <ul>
            <li><span class="file">Item 1.1</span></li>
        </ul>
    </li>
    <li><span class="folder">Folder 2</span>
        <ul>
            <li><span class="folder">Subfolder 2.1</span>
                <ul id="folder21">
                    <li><span class="file">File 2.1.2</span></li>
                </ul>
            </li>
        </ul>
    </li>
    <li class="closed"><span class="folder">Folder 3 (closed at start)</span>
        <ul>
            <li><span class="file">File 3.1</span></li>
        </ul>
    </li>
    <li><span class="file">File 4</span></li>
</ul>

jQuery

$("#browser >li").click(function(clk){
    var $val = clk.target.childNodes[0].nodeValue
    $("#workspace").attr('value',$val);
});

preguntado el 08 de noviembre de 11 a las 09:11

1 Respuestas

Just remove the "$" on $val variable !

jsfiddle and chrome developer tools are good way to debug simple code.. http://jsfiddle.net/bouillard/PUjHf/

respondido 08 nov., 11:14

That's not the problem, a variable can start with $. - xdazz

OK... sorry... Then try to debug with chrome and developer tools ! - Benoît

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.