|
how to call functionname within a function
i define a function named add_tag and want to call this function with the jquery function (#example).keypress(). what i hope for is when i input something in the input form with id=example, then the function named add_tag will be executed. I know how to call the function within html, but just want to call it within a function.
$("#example").keypress(function() {
add_tag(event.which)
});
function add_tag(keycode) {
if (keycode == 13) {
var tag = $(event.target).val();
var current = new Date();
var tag_id = "tag" + current.getTime();
var tags = sprintf('<dt id="%1$s" class="tags">%2$s<a href="#" onclick=$("#%1$s").remove()>X</a></dt>', tag_id, tag);
$("#submitted-tags").append(tags);
}
};
|