Question about Ajax callback functions
I currently have several functions in my document.ready handler which are working fine. Two are designed to apply css styling to select elements:
- $('select.third').filter(function(){return $(this).val() == '1'; }).css({backgroundColor: 'yellow'});
- $('select.fourth').filter(function(){return $(this).val() == '0'; }).css({backgroundColor: 'red'});
and another makes an Ajax call to change the sort order of the elements when the user changes a select element:
- $('select#searchtype').change(function(event){
- var searchtype = $(this).val(),
- token = $('#token').val();
- $('div#allSheepDisplay').contents().remove().end().load(
- 'db-interaction/animals.php',
- {
- action: 'sort',
- searchtype: searchtype,
- token: token
- }
- );
- // the following are not working after the Ajax call completes
- $('select.third').filter(function(){return $(this).val() == '1'; }).css({backgroundColor: 'yellow'});
- $('select.fourth').filter(function(){return $(this).val() == '0'; }).css({backgroundColor: 'red'});
- });
I want the css styling rules to be updated after the Ajax call completes, but inserting the function calls at lines 13/14 ain't working. Do I need to use an .ajax() call instead of the .load() call, and have the callback function call these two functions? Or is there another solution?