jQuery Multiple Selector
Bu gün jQuery multiple selector ile birlikte, not() ve :first kullanmam gerekti.
Amele yazımıyla aşağıdaki şekilde olabilecek bir kodu, daha mantıklı bir yoldan çözelim.
$('#select0').children().not(':first').remove();
$('#select1').children().not(':first').remove();
$('#select2').children().not(':first').remove();
$('#select3').children().not(':first').remove();
Aslında kompleks bir kullanım olmamasına rağmen, jQuery mantığına ters olduğu için aşağıdaki satır çalışmadı.
$('#select0, #select1, #select2, #select3').children().not(':first').remove();
Bu şekilde kullanımda, jQuery tüm selectorlerin sonucunu alıp, daha sonra children(), daha sonra .not(‘:first’)'e bakıp sondaki remove() functionunu çalıştırıyor.
Her bir selector için .children().not(‘:first’).remove(); çalıştırmamız lazım.
Çözüm işte burda :
$('#select0, #select1, #select2, #select3').each(function(key, value){
$(value).children().not(':first').remove();
})
each kullanarak her bir selector için ayrı ayrı remove etmiş olduk.
