Combine HTML onClick attribute with jQuery On?

Where I work with deprecated onclick functions on input elements:

<input name="input_41" type="radio" value="76" id="choice_41_1" onclick="gf_apply_rules(5,[6,7,8]);">

Unfortunately, I cannot directly modify or modify legacy code.

I am also trying to update the site and make the form elements more beautiful with the help of additional CSS and JS. One of the new features that I use to process radio elements uses the jQuery function On(). This function works well, but seems to override the existing onclick function gf_apply_rules(). Here is a jQuery example:

$(document).on('click.radio.data-api', '[data-toggle^=radio], .radio', function (e) {
    var $radio = $(e.target);
    e && e.preventDefault() && e.stopPropagation();
    if (!$radio.hasClass('radio')) $radio = $radio.closest('.radio');
    $radio.find(':radio').radio('toggle');
});

Anyway, can I save a valid onclick HTML pointer with On()?

+4
source share
1 answer

e.preventDefault() ( ) onclick. , , .,

+6

All Articles