In the script below, the “my_theme” element is a select list of a directory listing.
When its “change” event is fired, the jquery is called and triggers a “get” to find out if the selected folder has a style.css file. The get returns true/false.
All that works fine. I’m just trying to determine how to decorate the item in the select list depending on the outcome of the get.
For example, if its false, I want to make the selected item’s background gray and append some text to the option name label.
So, if the currently selected item in the list is “alpha”, and the $.get returns false, then the text should become “alpha (inactive)”.
$('#my_theme').change
(
function()
{
//check if this folder has a style.css file
$.get('<?php echo get_bloginfo('template_directory') ?>/getStyle.php', {theme: myImage}, function(data){doActive(data);});
}
);
function doActive(data){
if(active){
//if the stylesheet is missing, append the label with " (inactive)"
$('#my_theme :selected').text() = $('#my_theme :selected').attr('value') + ' (inactive)';
}
the option’s “value” attribute is the same as its label.
}
1 Answer