jQuery change function not working
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>
</开发者_JS百科select>
<p class="hiddentext" style="display:none">TEXT</p>
Any ideas?
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();
}
});
});
I think you are missing ;
Check here
精彩评论