Solved

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

Posted on 2013-01-15
3
479 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
ID: 38780962
Try this:
 $("#menu-selector").change(function () {
                $("#" + $(this).val()).fadeIn('slow');
            });

Open in new window

0
 
LVL 3

Expert Comment

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

Open in new window

0
 

Author Closing Comment

by:vacpartswarehouse
ID: 38782904
This is perfect! Thank you so much!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

808 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