Using a JS variable for click event ID

Is it possible to use a variable for the ID of a click event…like this:

this_id = '\'#' + form_id + '\'';

$(this_id).on('click', function(event) {

 });

I am trying this without success

Hi @henk3, you can use any valid CSS selector, just remove the escaped quotes…

what about the # that specifies its an id im looking for?

Again, you can use any valid CSS selector, including ID selectors.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.