JSFiddle - React, Tailwind, and code Playground

by alfredopacino

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>



<input id="mySelect1" />
<input id="mySelect2" />


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>

<select class="js-example-basic-single" multiple style="width:100%">
    <option value="AL">Alabama</option>
    <option value="WY">Wyoming</option>
</select>
    <script>

        $(document).ready(function() {
            $('.js-example-basic-single').select2({
                templateResult: r => {
                    return `<span><label>ID</label> ${r.id} <p><label>TEXT</label> ${r.text}</p></span>`;
                }
            });
        });
        
        $('#mySelect1').select2({
            ajax: {
                url: 'https://api.github.com/search/repositories',
                dataType: 'json'
                // Additional AJAX parameters go here; see the end of this chapter for the full code of this example
            }
        });

        $('#mySelect2').select2({
        ajax: {
            url: 'https://api.github.com/search/repositories',
            processResults: function (data) {
                // Transforms the top-level key of the response object from 'items' to 'results'
                return {
                    results: data.items
                };
            }
        }
    });
</script>
</body>
</html>