After JQuery Version Upgrades to 3.5.0 from 2.14, I am receiving the following error, but I did not fully understand what the problem is,there is radio = event.target The error I received in the definition of Cannot Read Properties of Undefined (Reading 'target') Anyone can you help me solve?*
var testMethod = {
testSubMethod: function (event) {
var radio = event.target;
var isMultiInput = $('#MultipleInputYes').is(':checked');
if (!isMultiInput || radio.value == undefined) {
$('.divMultiInput').addClass("dp-none");
if (radio.value == 'false') {
$('#divInputValueType').prop('disabled', false);
$('#divInputValueType').attr('style', '');
}
}
},
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/js/select2.min.js"></script>
<div class="radio radio-success">
<input type="radio" id="MultipleInputYes" value="true" name="IsMultiInput" onchange="testMethod.testSubMethod(this)">
<label for="MultipleInputYes"> Yes</label>
</div>
<div class="radio radio-success">
<input type="radio" id="MultipleInputNo" value="false" checked="checked" name="IsMultiInput" onchange="testMethod.testSubMethod(this)">
<label for="MultipleInputNo">No</label>
</div>
I belive event must be undefined in
var radio = event.target;
so that when you try to access event.target you are accessing target property of undefined which is an error in javascript
try checking if event is defined first
var radio = event ? event.target : undefined
testMethod.testSubMethod(this) this - referenced to html object in you case.
So probably changing
testSubMethod: function (event) {
var radio = event.target;
to something like this may fix your problem
testSubMethod: function (el) {
var radio = el;