2
$("body").on("click", "$[id *= ddlHour]",
        function () {
            ValidateDate();
        }
    );

This is working fine in jQuery 1.7.1 but when I upgrade to 1.12.4 it gives the following error:

Uncaught Error: Syntax error, unrecognized expression: $[id *= ddlHour]

I tried

$("body").on("click", "$('[id*=\"ddlHour\"]')",
        function () {
            ValidateDate();
        }
    );

but I am still getting the same error. Does anyone know what is going wrong?

Robert Columbia
  • 6,313
  • 15
  • 32
  • 40

1 Answers1

0

I'm surprised that worked in an older version of jQuery, since the selector is invalid. That leading $ shouldn't be there. It's just:

$("body").on("click", "[id *= ddlHour]",
//                     ^−−−−−−−−−−−−−−−−−−−−− No $ here
    function () {
        ValidateDate();
    }
);

More in the CSS specification.


Side note: Unless you explicitly want to prevent ValidateDate from receiving the event object that it would receive if it were hooked up directly, and/or want to prevent ValidateDate returning false to stop event propagation, you could just write:

$("body").on("click", "[id *= ddlHour]", ValidateDate);
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875