Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
136
rated 0 times [  143] [ 7]  / answers: 1 / hits: 31046  / 10 Years ago, wed, august 27, 2014, 12:00:00

I have a drop down with set of 'ul' and 'li' like this,



<div style=float:left;>
<div class=group>
<div style=width:80px;>Dropdown<i class=fa fa-caret-down></i></div>
<ul style=float:left;>
<li><a href=javascript:void(0);>Option1</a></li>
<li><a href=javascript:void(0);>Option2</a></li>
<li><a href=javascript:void(0);>Option3</a></li>
</ul>
</div>
</div>


I want to add onchange() event to ul tag. I can say onchange i have to call one function SelectedItem(optionselected) with selected 'li' text as parameter.Anyone Please help me. Thank you.


More From » jquery

 Answers
6

The change event is sent to an element when its value changes. This
event is limited to elements, <textarea> boxes and
<select> elements. For select boxes, checkboxes, and radio buttons,
the event is fired immediately when the user makes a selection with
the mouse, but for the other element types the event is deferred until
the element loses focus.




see http://api.jquery.com/change/



So .change() doesn't work on an unordered list...



Use click event for it



    $('li').click(function(){
//your code
});

[#69643] Monday, August 25, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jameson

Total Points: 534
Total Questions: 103
Total Answers: 102

Location: Lithuania
Member since Fri, Sep 4, 2020
4 Years ago
jameson questions
;