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); });
Comments
Post a Comment