I am learning jQuery. I am trying to understand the choices. Therefore, when the user selects a parameter, I can do something.
I am trying to run jquery so that the user, by selecting userAmountSelected, should add the class 'xxx' to customAmountinput
$(document).ready(function() {
if ($("#amountSelected:selected").val() == 'customAmountSelected') {
$('.customAmountinput').addClass('xxx');
}
});
.displaynone {
display: none;
}
<div>
<div class="form-group">
<label>Budget (£)</label>
<select class="form-control" id="amountSelected">
<option selected="selected">No budget</option>
<option value="5">£5</option>
<option value="30">£10</option>
<option value="20">£20</option>
<option value="50">£50</option>
<option value="100">£100</option>
<option value="customAmountSelected">Custom</option>
</select>
<p class="small"><em>Need some text here to explain why they can edit budget </em>
</p>
</div>
<div class="form-group displaynone customAmountinput">
<label>Enter ammount</label>
<input class="form-control" placeholder="£">
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" value checked>Post to wall?
</label>
</div>
</div>
</div>
Run codeHide result
source
share