I already filtered a select
element for non multiple selects :
$("select:not([multiple])").select2().on("change", function(e) {
if ($(this).val() == "") {
$(this).parent().find("span[role='combobox']").each(function() {
$(this).attr("data-validate-func", "required").attr("data-validate-hint", "<?php echo _getText('global.champ.obligatoire'); ?>");
});
} else {
$(this).parent().find("span[role='combobox']").each(function() {
$(this).removeAttr("data-validate-func");
});
}
});
Now I want to filter also for select
elements not having a Label
as its first parent
. How to modify my code for that purpose ?
You can use .filter()
:
$("select:not([multiple])").filter(function(){
return $(this).parent().is('label')
}).select2().....
You can add a descendant selector to your :not
clause:
$("select:not([multiple], label > select)").select2().on("change", //...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.