need get link text from selected li menu with jquery -


when click on li menu, need link text. problem menu tree , current text parent text.

for example - when clik on "test 3" , "test 2". in situation need "test 3".

i can change jquery script, html code generate cms.

my code:

<script> $(document).ready(function(){     $("#menu li").click(function() {         var text = $(this).children('a').text();         alert(text);             }); }); </script> <div id="menu">         <ul>             <li><a href="#">test 1</a></li>             <li>                 <a href="#">test 2</a>                 <ul class="sub_menu">                     <li><a href="#">test 3</a></li>                     <li><a href="#">test 4</a></li>                 </ul>             </li>             ....         </ul>     </div> 

$("#menu li").click(function(e) {     e.stoppropagation();     var target = e.target,         text = target.textcontent || target.innertext;     console.log(text);         }); 

js fiddle demo.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -