Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resetting all select2 jquery select elements

Tags:

jquery

I need to reset couple of select2 select element. Currently i am doing it as follows

            $("#ItemId").select2("val", "");
            $("#PermanentDistrictId").select2("val", "");
            $("#PermanentThanaId").select2("val", "");
            $("#PresentDistrictId").select2("val", "");
            $("#PresentThanaId").select2("val", "");
            $("#OccupationId").select2("val", "");
            $("#GenderId").select2("val", "");

But i would like to do it in single function like as follows-

ParticularForm.AllSelectElements.select2("val", "");

I am asking here as because my javascript skill is very poor. So, I need your help.

Thank you.

like image 901
s.k.paul Avatar asked Jun 01 '26 18:06

s.k.paul


1 Answers

$(".select2-hidden-accessible").val(null).trigger("change");

like image 52
Aba Avatar answered Jun 03 '26 06:06

Aba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!