fuelux

Fuel UX 3: is element id required for initialization through Javascript?


I am new to Fuel UX and trying to make checkbox work. I have the following simple page:

<!DOCTYPE html>
<html lang="en" class="fuelux">
<head>
    <meta charset="utf-8">
    <title>Fuel UX 3</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="dist/css/fuelux.min.css" rel="stylesheet" type="text/css">

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    <script src="//www.fuelcdn.com/fuelux/3.11.0/js/fuelux.min.js"></script>


</head>
<body>

    <div class="checkbox" id="myCheckbox">
        <label class="checkbox-custom" id="myCustomCheckbox1">
            <input class="sr-only" type="checkbox" value="">
            <span class="checkbox-label">Custom checkbox unchecked on page load 22234</span>
        </label>
    </div>
    <script>
           //javascript initialization goes here
    </script>    
</body>
</html>

I need to initialize the checkbox via Javascript. The following works:

$('#myCustomCheckbox1').checkbox();

The following are not working:

$('input[type="checkbox"]').each(function(index, item) {
    $(this).checkbox();
});

or

$('input[type="checkbox"]').checkbox()

Could any expert confirm that checkboxes must have id if they are initialized via Javascript? Or I did it in a wrong way?


Solution

  • Please review the documentation. The checkbox jQuery plugin can only be bound to the label, not the wrapping div (if present), nor the input.

    You might try:

    $('.checkbox > label').each(function(index, item) {
        $(this).checkbox();
    });