Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   JSTREE как получить id parent????? (https://javascript.ru/forum/jquery/23560-jstree-kak-poluchit-id-parent.html)

dsnj 28.11.2011 00:31

JSTREE как получить id parent?????
 
<body>

<div id="wrap">
    <div id="header">header</div>
    <div id="main">
        <div id="demo1" style="float:left;width:50%;">
            <ul>
                <li>
                    <a class="aa" id='a' href="">aaa</a>
                    <!-- UL node only needed for children - omit if there are no children -->
                    <ul>
                        <li><a class="ab" id="a_1" href="#"> bbb</a></li>
                        <li><a class="ab" id="a_2" href="#"> ccc</a></li>
                    </ul>
                </li>
            </ul>

        </div>
        <div id="content">www</div>
    </div>
</div>

<div id="footer">
    footer
</div>

<script type="text/javascript">
$(function () {
    $("#demo1").jstree({
        "themes": {
        "theme": "default",
        "dots": true,
        "icons": true,
      },

        "plugins" : [ "themes", "html_data", "ui" ]
    });
   $('.ab').click(function(){
            var id_ab = $(this).attr('id');
            var id_aa = $(this).parent().attr('id');
            $('#content').html('ab \'s content, ID_ab = ' + id_ab + ' ID_aa = ' + id_aa); 
        })    
            
});
</script>


</body>


В РЕЗУЛЬТАТЕ получаю след. контент: 'ab 's content, ID_ab = a_1 ID_aa = undefined

ПОМОГИТЕ В ПОЛУЧЕНИИ ID родителя элемента!!!

ЗАРАНЕЕ СПАСИБО!!!

melky 28.11.2011 00:38

$(this).parent("div").attr("id");

dsnj 28.11.2011 00:40

Цитата:

$(this).parent("div").attr("id");
попробовал вставить "div" - результат не поменялся...(

melky 28.11.2011 00:43

какой id должен быть на выходе ?

dsnj 28.11.2011 00:44

id='a'

melky 28.11.2011 00:48

Цитата:

Сообщение от dsnj (Сообщение 139397)
ПОМОГИТЕ В ПОЛУЧЕНИИ ID родителя элемента!!!

O_o так это не родитель.

как-то так.
$(this).parent("ul").parent('li').find('a:first[id]').attr('id')

dsnj 28.11.2011 00:52

а что
find('a:first[id]')
делает?? опять результат UNDEFINED

melky 28.11.2011 00:54

ищет первую <a> , у которой есть атрибут id.

dsnj 28.11.2011 00:57

опять результат UNDEFINED

melky 28.11.2011 00:58

тьфу. с просонья букву забыл
$(this).parent*!*s*/!*("ul").parent('li').find('a:first[id]').attr('id');


Часовой пояс GMT +3, время: 20:25.