0

I use jQuery to create HTML elements (specifically, to add a row to a table), but I want to use the generated elements in jQuery. What I came up myself is this:

function add_row() {
    var id = Math.floor(Math.random() * 100000);

    $("#properties").append('<tr>'+
        '<td><input id="'+id+'" type="text" name="myInput"></td>'+
    "</tr>");

    $("#"+id).bind('keydown', hotkey.toLowerCase(), function() {
        do_stuff();
    });
}

Note that I use https://github.com/jeresig/jquery.hotkeys to bind to the input. It doesn't seem to support the on way.

But this feels a little clunky. Is there a better way?

Bart Friederichs
  • 32,037
  • 14
  • 96
  • 185

0 Answers0