0

I am trying to add the function of selecting and deselecting all fields. What I have now doesn't work for me and I don't know why? Does anyone know why?

.....
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://igoradamenko.github.io/awsm.css/css/awsm.min.css">
    <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
    <title>Report</title>
    <script>
        $("#selectAll").click(function() {
            $("input[type=checkbox]").prop("checked", $(this).prop("checked"));
        });
    </script>
</head>
....

 <label for='selectAll'><input id="selectAll" type="checkbox">Select All </label>
            <input checked="checked" type="checkbox">Test</label>
            <label th:each="item : ${userConfig.isEnableMap}">
                <input checked="checked" type="checkbox" th:text="${item.key}" th:field="*{isEnableMap['__${item.key}__']}"/>
            </label>

I added changes and it works now

<script>
    $(document).ready(function () {
        $("#selectAll").change(function () {
            $("input:checkbox").prop('checked', $(this).prop("checked"));
        });
    });
</script>
Dev007
  • 366
  • 1
  • 12

1 Answers1

0

You can try :

$("input[type=checkbox]").prop("checked",true);