Solved

jQuery: Slide Down Pretty Select on Hover

Posted on 2013-05-22
2
480 Views
Last Modified: 2013-06-03
Now you have to click on "Choose One" to see the drop down options.  I want the options to slide down so you can see them when you hover over "Choose One".
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

 pretty_selects();

});
	
function pretty_selects() {
        $('.styled-select').each(function () {
            $(this).wrap('<div class="pretty-select" />')
            $('<div class="select-text" />').prependTo($(this).parent('.pretty-select'));
            $(this).parent().children('.select-text').text($(this).attr('name').replace(/_/gi, ' '));
        }).change(function () {
            $(this).parent().children('.select-text').text($(this).children('option:selected').text());
        });
}

</script>
<style type="text/css">

body {
background: #eeeeff;
}

.pretty-select{
	height: 35px;
	position: relative;
	width:200px;
}

.pretty-select .select-text{
	height: 35px; 
	line-height: 35px;
	text-indent: 10px;
	color: #fff;
	background: #aaa;
	border: 1px solid #222;
}

.pretty-select select{	
	width: 100%;
	position: absolute;
	top: 0;
	right: 0; bottom: 0;
	opacity: 0;
	filter:alpha(opacity=0);
}
.pretty-select select option{
	padding: 5px 0;
	text-indent: 10px;
	border-bottom: 1px dotted #ccc;
}
.pretty-select select option:hover{
	background-color: #d6d6d6;
	cursor: pointer;
}

</style>
</head>
<body>

<select name="Choose_One" class="styled-select"> 
<option value="a">Option 1</option> 
<option value="b">Option 2</option> 
<option value="c">Option 3</option> 
<option value="d">Option 4</option> 
<option value="e">Option 5</option> 
</select> 

</body>
</html>

Open in new window

0
Comment
Question by:hankknight
2 Comments
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
Comment Utility
0
 
LVL 6

Accepted Solution

by:
mickey159 earned 500 total points
Comment Utility
It is impossible to open a <select> by using hover. However, it is possible to use a drop down menu. Therefore, if the value is not going to be submitted in a form, try replace it with a drop down menu.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
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…

772 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

10 Experts available now in Live!

Get 1:1 Help Now