JQuery change function not working

It seems to me that this work does not seem

$('.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?

+5
source share
3 answers

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)

+13
source

Make sure you put this in $(document).readyso that the DOM is ready when you attach the handler .change():

$(function() {
    $('.titleother').change(function() {
        if ($(this).val() == 'Other') {
            ​$('.hiddentext').show();
        }​​​
    });
});
+5
source

I think you are missing Check here;

+4
source

All Articles