Issue
I have some jQuery code that filters out a list of links on the page. At present the filtering is fired when a link with a blind href is clicked. The id of the link is taken to determine which content remains visible on the page. EG:
<script type="text/javascript">
$(document).ready(function () {
//when a link in the filters div is clicked...
$('#filters a').click(function (e) {
//prevent the default behaviour of the link
e.preventDefault();
//get the id of the clicked link (which is equal to classes of our content
var filter = $(this).attr('id');
//show all the list items (this is needed to get the hidden ones shown)
$('#content ul li').show();
/*using the :not attribute and the filter class in it we are selecting
only the list items that don't have that class and hide them '*/
$('#content ul li:not(.' + filter + ')').hide();
});
});
</script>
I need to changed this so that, the jQuery is activated when an option is changed in a DropDownList/SELECT. However, I can't quite get my head around how to change this JScript to detect the selection in the DDL rather than a hyperlink.
Solution
Use the change() event
$("#idOfDropDown").change(function() {
//code here
var filter = this.value //gets the value of the selected dropdown item.
});
This will fire each time a dropdown selection has been made.
Answered By - tymeJV
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.