I can't seem to get this working seems like it should
$('.titleother').change(function() {
if ($('.titleother').val() == 'Other') {
$('.hiddentext').css('display','block')
}
})
For this HTML
<select class="titleother">
<option value="1">1</option>
<option value="2">2</option>
<option value="Other">Other</option>
</select>
<p class="hiddentext" style="display:none">TEXT</p>
Any ideas?
The change() method triggers the change event, or attaches a function to run when a change event occurs. Note: For select menus, the change event occurs when an option is selected. For text fields or text areas, the change event occurs when the field loses focus, after the content has been changed.
on if not a function" jQuery error occurs for 2 main reasons: Loading an old version of the jQuery library that doesn't support the on function. Loading a library that overrides the value of the dollar sign $ variable.
There are two methods of getting the value of the selected option. You can either select text or find the position of it in a drop-down list by using the option:selected attribute or the val() method in jQuery. The val() method returns the value of selected attribute value.
This works for me using Chrome:
$(function(ready){
$('.titleother').change(function() {
if ($(this).val() == 'Other') {
$('.hiddentext').show();
}
});
});
http://jsfiddle.net/amuec/11/
(Darin's code didn't work for me either)
Make sure you put this in a $(document).ready
so that the DOM is ready when you attach the .change()
handler:
$(function() {
$('.titleother').change(function() {
if ($(this).val() == 'Other') {
$('.hiddentext').show();
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With