CMS Development

jesusgonzalez20
Member

create "optgroup" inside from a "select"

Hi everyone, are there any way to create "optgroup" inside from a "select" in the form?

Any could show me an example, please

 

I tried of this way but didn't work

 

var selects = document.querySelectorAll("select");
    for (var i = 0; i < selects.length; i++ ){
selects[i].appendChild(document.createElement("optgroup"));
}

 

and another example that I tried is this:

var foundin = $('#pruebaoptgroup  options:contains("optgroup-")');
$.each(foundin, function(value){
var updated = $(this).val().replace('optgroup-','');
$(this).nextUntil('option:contains("endoptgroup")').wrapAll('<optgroup label="'+updated+'"></optgroup>');
});
$('#pruebaoptgroup options:contains("optgroup-")').remove();
$('#pruebaoptgroup options:contains("endoptgroup")').remove();

 
0 Upvotes
1 Reply 1
vish891
Member

create "optgroup" inside from a "select"