How to retrieve a clicked element in a Jquery treeview -


i willing use jquery treeview. have categories , subcategories choose item , display them in treeview. clicked value.

for moment working on of kind of :

<ul id="treeview">     <li>group1a         <ul>             <li>group11 </li>         </ul>     </li>     <li>group2 </li>     <li>group3 </li>     <li>group4 </li>     <li>group5 </li> </ul> 

and tried script, click function throw me error.

<script type="text/javascript">             $().ready(function () {                 $("#treeview").treeview();             });              $("#treeview").click(function (e) {                 e.target.addclass("selected");             });  </script> 

i big beginner jquery way of handling things, assume missing important point somewhere... help..

the addclass jquery method, while e.target not jquery object. need enclose in $():

$("#treeview").click(function (e) {     $(e.target).addclass("selected"); }); 

your code won't work anyways, click event bound #treeview element, , when element fires, e.target #treeview element. you're looking this:

$("#treeview li").click(function() {     $(this).addclass("selected"); }); 

this binds click function li elements, , when 1 of them clicked, adds "selected" class element.

probably want allow deselecting of objects, should use toggleclass instead of addclass. if want allow selecting of 1 object, use this:

$("#treeview li").click(function() {     // clear selected states     $('#treeview li').removeclass('selected');     // set current selected     $(this).addclass("selected"); }); 

hope helps.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -