Solved

Change HTML class based on select option value through JavaScript/jQuery

Posted on 2013-01-15
3
475 Views
Last Modified: 2013-01-16
I have a long list of options in a select menu.

<select name="top-menu" id="menu-selector">
	<option value="#">Choose a category</option>
	<option value="ABC">ABC</option>
	<option value="DEF">DEF</option>
	<option value="GHI">GHI</option>
</select>

Open in new window

When an option is selected, jQuery will fade in a new select menu based on the value of that option. In other words, choosing ABC will fade in another select menu where id="ABC". As of right now, I have this.

$(document).ready(function (){
	$("#menu-selector").change(function() {
		document.getElementById($(this).val()).fadeIn('slow');
	});
});

Open in new window

However, that's not working. It throws this error:
Uncaught TypeError: Object #<HTMLSelectElement> has no method 'fadeIn'

Open in new window

How can I fix this?
0
Comment
Question by:vacpartswarehouse
3 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
Comment Utility
Try this:
 $("#menu-selector").change(function () {
                $("#" + $(this).val()).fadeIn('slow');
            });

Open in new window

0
 
LVL 3

Expert Comment

by:Khilu
Comment Utility
 $("#menu-selector").change(function () {
   $(this).fadeIn('slow');
            });

Open in new window

0
 

Author Closing Comment

by:vacpartswarehouse
Comment Utility
This is perfect! Thank you so much!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now