Categories: Jquery

How to Select All element of SELECT2

Select2 is very famous jquery plugin for HTML Select-control. Select2 also supports multi-value select boxes. Select2 is very easy to use and configurable.

Select2 provides you a customizable select box with support for searching, tagging, remote data sets, infinite scrolling, and many other highly used options.

Also, check out other tutorials of select2,

How To Apply Select2 On HTML Select Element

$("#selectId").select2();

as u can see, I have used select2() method on HTML dropdown which id is #selectId.

Related Post

I will tell you how to select all elements of the multi-select box onClick() of a particular option, ie. if you have the option ‘all’ in a multi-select box and you need to select all elements of multi-select when the user select 'All' option.

Select All Options of select Box Using Select2

The following code needs to use select all options of the multi-select box,

$('#selectId > option').prop("selected",true);

Also trigger a change event if you want to reflect the changes on the interface too.

$('#selectId > option').prop("selected",true).trigger("change");

Clear All Selected Options

You can also clear all selected options.

$('#selectId > option').prop("selected",false).trigger("change");

View Comments

Recent Posts

Configure and Retrieve S3 Information Using Laravel PHP-AWS-SDK

This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More

2 months ago

What is the Purpose of php_eol in PHP?

in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More

8 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

8 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

9 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

9 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

9 months ago

Categories