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) {
$('.divMultiInput').removeClass("dp-none");
$('.divMinMaxVal').addClass("dp-none")
$('#divMinMaxDate').addClass("dp-none")
$('#divRgxWarnMsg').addClass("dp-none")
$('#minValueInpt').val('');
$('#maxValueInpt').val('');
$('.divInputValUpper').addClass("dp-none");
$('[name=ValueType]').val('');
$('#inputValueTypeSelect').removeClass('required');
$('#inputValueTypeSelect').removeClass('customError');
}
else if (!isMultiInput || radio.value == undefined) {
$('.divMultiInput').addClass("dp-none");
$('.divMinMaxVal').removeClass("dp-none");
$('#divMinMaxDate').removeClass("dp-none");
$('#divRgxWarnMsg').removeClass("dp-none")
$('.divInputValUpper').removeClass("dp-none");
$('[name=ValueType]').val('1');
$('#inputValueTypeSelect').addClass('required');
$('#divWarnMsg').css("display", "inherit");
$('#placeHolderInpt').val('');
$("#maskInpt").select2("val", "");
if (radio.value == 'false') {
$('#divInputValueType').prop('disabled', false);
$('#divInputValueType').attr('style', '');
}
$('#htmlEditorDiv').css("display", "inherit");
$('#useMultiLineDiv').css("display", "inherit");
$("#Tags").tagit("removeAll");
}
},
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
<div >
<input type="radio" id="MultipleInputYes" value="true" name="IsMultiInput" onchange="testMethod.testSubMethod(this)">
<label for="MultipleInputYes"> Yes</label>
</div>
<div >
<input type="radio" id="MultipleInputNo" value="false" checked="checked" name="IsMultiInput" onchange="testMethod.testSubMethod(this)">
<label for="MultipleInputNo">No</label>
</div>
CodePudding user response:
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;