Show and hide html element on selected option change

前端 未结 10 1690
耶瑟儿~
耶瑟儿~ 2021-01-12 04:31

In a JSP page, I have a dropdown list. When the first element of the list is selected, I want a text area to show right on click. I\'m new to Javascript/Jquery, so I\'m obvi

10条回答
  •  Happy的楠姐
    2021-01-12 04:57

    Try this code:

    // This will create an event listener for the change action on the element with ID 'show'
    $('#show').change(function() {
    
         // If checkbox is 'checked'
        if($(this).is(':checked')) {
            // show the element that has the id 'txt_area' 
            $('#text_area').show();
        } else {
            // hide it when not checked
            $('#text_area').hide();
        }
    });
    

提交回复
热议问题