manu padmanabhan
manu padmanabhan

Reputation: 59

Using jPicker in an EJS table

I am trying to add a jPicker inside my table <td>. I create the table using EJS in this way:

<table>
    <tr>
        <td><%= setting[i].name %></td>
        <td><span style="background-color: red" class="Alpha"></span></td>
    </tr>
</table>

In the last td I add the span for the color picker. The code for jPicker is this:

$('.Alpha').jPicker({
    window: {
        expandable: true
    }
});

Why is this not working inside the EJS table? I just checked it in a regular table and it's working.

Upvotes: 0

Views: 46

Answers (1)

Graham Shroll
Graham Shroll

Reputation: 291

If no .Alpha elements are being matched, this is probably because none exist yet when that code is running.

Make sure your $('.Alpha').jPicker() code comes after the table in your ejs file, or that you're wrapping inside $(document).ready() or similar to make sure it waits for the DOM to finish being written before trying to match elements in it e.g.:

$(document).ready(function(){
    $('.Alpha').jPicker({
        window: {
            expandable: true
        }
    });
});

Upvotes: 0

Related Questions