Open In App

How to display div elements using Dropdown Menu in jQuery?

Last Updated : 20 Sep, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
In order to display data/content of a specific element by selecting the particular dropdown menu in jQuery, we can use the with following ways:
  1. Using hide() and show() methods:
    • hide() methods : This method is used to hiding the syntax or the element of html that you want to hide. Syntax:
      $(selector).hide(speed, callback);
    • show() methods : This method is used to show the syntax or the element of html that you want the user to see. Syntax:
      $(selector).show(speed, callback);
    Approach:
    • Selector name for dropdown menu is same as the element which is used to display the content.
    • Store the values of the selected elements in variable using .attr() method.
    • Now check for the element whether any element is selected or not.
    • If yes, use show() method for displaying the element for the selected element, otherwise use hide() method for hiding.
    Example 1:
    Output: Before selecting the any radio button: After selecting the radio button: Example 2: Along with alert method
    Output:
  2. Using css() method: .css() method: This method in JQuery is used to change style property of the selected element. Syntax:
    $(selector).css(property)
    Approach:
    • Selector name for dropdown menu is same as the element which is used to display the content.
    • Find the selected element from list using .find() method.
    • Now check for the element which element is selected.
    • Now change the display property of selected element using .css() method.
    Example:
    Output: Before selecting the any radio button: After selecting the radio button:

Article Tags :

Similar Reads