Show and hide html element on selected option change

前端 未结 10 1687
耶瑟儿~
耶瑟儿~ 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条回答
  •  耶瑟儿~
    2021-01-12 05:00

    You are getting the html element by document.getElementById that returns normal javascript object. Jquery methods hide() and show() are available for jquery objects only.

    But whatever you want to achieve can be achieved by simple Javascript, just made some simple changes.

    instead of show() and hide() use respectively textarea.style.display = "block" and textarea.style.display = "none";

    and remove the ); in the end of your code.

    use the fiddle link for working example. fiddle link

提交回复
热议问题