Edit : I am aware that their is a question mark in the jQuery, CSS and HTML. Due to it being generated automatically by Yii I cannot remove it.
Using jQuery I am attempting to add and remove styling to an input and label within my HTML. I get no response when I am trying this, I believe it is due to the abnormal for="" and/or val= values of the elements generated by Yii.
Can't seem to get it working with the if else statement. When removed it applies the CSS.
It should do as follows; select Yes, with the value "Yes", and the second label and input appear.
I have created a CodePen for this as I am having issues with JSFiddle. https://codepen.io/CallumRocks/pen/rwrrvE
I have also included the relevant code below.
$(document).ready(function(){
$('#event_Do_you_require_any_accessibility_assistance?').on('change',function(){
if($(this).val() == 'Yes'){
$("label[for='event_Please specify']").css('display', 'block');
$("input#event_Please_specify").css('display', 'block');
}
else {
$("label[for='event_Please specify']").css('display', 'none');
$("#event_Please_specify").css('display', 'none');
}
});
});
label[for="event_Would you like to stay informed about updates and changes to this event?"] {
width: 100% !important;
line-height: 20px;
}
label[for="event_Please specify"] {
display: none;
}
input#event_Please_specify{
display: none;
}
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<div class="form-group">
<label class="required-label required" for="event_Do you require any accessibility assistance?">Do you require any accessibility assistance? <span class="required">*</span></label>
<select class="form-control user-success" required="required" name="event_Do you require any accessibility assistance?" id="event_Do_you_require_any_accessibility_assistance?">
<option value="">Please choose</option>
<option value="Yes">Yes</option>
<option value="No"> No</option>
</select>
</div>
<div class="form-group">
<label for="event_Please specify">Please specify</label>
<input class="col-md-5 form-control" placeholder="Please specify" autocomplete="off" type="text" value="" name="event_Please specify" id="event_Please_specify">
</div>
?.