I'm working on an ajax select box that loads file content into the closest div area Demo. I'm using the script below to change the first option text "Select" to "Hide" when the ajax content is loaded.However, I can't get the "Hide" text to change back to "Select" after on clicking it.
Code:
var area = $(".selectboxarea");
$(".searchselectbox").on('change', function (e) {
area.empty();
var selected = $(this).find('option:selected');
var loadfile = selected.data('file');
if (loadfile) {
$(this).next('.selectboxarea').load(loadfile);
$(this).find('option:contains("Select")').text("Hide");
} else {
window.location.href = $(this).val();
}
});
HTML
<select class="searchselectbox">
<option value="#">Select</option>
<option data-file="fans.php">Fans</option>
<option data-file="stars.php">Stars</option>
</select>
<div class="selectboxarea"></div>
Should I use this line in a function?
$(this).find('option:contains("Hide")').text("Select");