cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="table"><div class="cell">
<div class="wrap">
    Dynamic, styleable select box:<br>
   <select class="myselect">
	<option disabled selected>Choose a country</option>
	<option value="FR">France</option>
	<option value="DE">Germany</option>
	<option value="IN">India</option>
	<option value="US">United States of America</option>
	<option value="JP">Japan</option>
	<option value="RS">Serbia</option>
	<option value="UK">United Kingdom</option>
</select>
</div>

<div class="wrap">
Native select box:<br>
<select>
	<option disabled selected>Choose a country</option>
	<option value="FR">France</option>
	<option value="DE">Germany</option>
	<option value="IN">India</option>
	<option value="US">United States of America</option>
	<option value="JP">Japan</option>
	<option value="RS">Serbia</option>
	<option value="UK">United Kingdom</option>
</select>
</div>
    </div>
</div>
            
          
!
            
              html,body{
    height:100%;
}
*{
    box-sizing:border-box;
}
.table{
    display:table;
    width:100%;
    height:100%;
}
.cell{
    display:table-cell;
    vertical-align:middle;
    text-align:center;
}
.wrap{
    display:inline-block;
    margin:10px 25px;
}
.jq-select{
	display:inline-block;
	position:relative;
    font-family:Arial;
    font-size:12px;
    text-align:left;
}
.jq-select *{
	margin:0px;
	padding:0px;
	box-sizing:border-box;
	list-style:none;
}
.jq-select .jq-selectbox{
	display: inline-block;
	position: relative;
}


/* DT styles for sliding doors */
.jq-select .jq-selectbox .jq-selected{
    display:block; 
	padding:2px 20px 1px 5px;
	width:auto;
	min-width:150px;
	border: 1px solid #a6a6a6;
	cursor:default;
	position:relative;
    white-space:nowrap;
}
.jq-select .jq-selectbox .jq-selected:after{
	position:absolute;
	content:'';
	display:block;
	top:50%;
	right:5px;
	margin-top:-2px;
	border-top:6px solid #000;
	border-right:4px solid transparent;
	border-left:4px solid transparent;
}

/* UL styles */
.jq-select ul { 
	background-color:#fff;
	display:none;
	list-style:none; 
	position:absolute; 
	left:0px;
	top:0px;
	min-width:100%;
	overflow:hidden;
    z-index:1;
}
.jq-select .jq-selectbox.open ul{
	display:block;
	border:1px solid #ccc;
}
.jq-select li{
	cursor:default;
	line-height:25px;
	padding-left:10px;
	padding-right:10px;
	display:block;
	position:relative;
	white-space:nowrap;
}

.jq-select li.selected{
    background-color:#eee;
}
.jq-select li.hover{
	background-color: #ccc;
}
.jq-select li.disabled{
	color:#ccc;
	background-color:transparent;
}

.jq-original{
    position:absolute;
    z-index:1;
    width:100%;
    height:100%;
    display:none;
}
.jq-original select{
	width:100%;
    height:100%;
    opacity:0;
    position:absolute;
    z-index:1;
}
.jq-original .outline{
    position:absolute;
    top:0px;
    left:0px;
    right:0px;
    bottom:0px;
    z-index:0;
}


@media all and (max-width:400px){
    .jq-original{
        display:inline-block;
    }
    .jq-original select:focus ~ .outline{
        outline-widthh: 2px;
        outline-style: auto;
        outline-color: Highlight;
        outline-color: -webkit-focus-ring-color;
    }
    
}
            
          
!
            
              $.fn.jQueryForm = function(classname){
	this.each(function(){
        var source = $(this);
        source.wrap('<div class="jq-select"></div>');
        var parent = source.parent();
        var selected = source.find("option:selected");  // get selected <option>
        var options = $('option', source);  // get all <option> elements

        // create <dl> and <dt> with selected value inside it
        source.after('<div tabindex="0" class="jq-selectbox '+classname+'">' +
            '<div class="jq-selected" data-value="'+selected.val()+'">' + 
                selected.text() + 
            '</div>' +
          '<ul></ul>' + 
       '</div>');
        source.wrap('<div class="jq-original"></div>').after('<div class="outline"></div>');
        
        if($('.jq-original', parent).css('display') != 'none'){
            $('.jq-selectbox', parent).removeAttr('tabindex');
        }
        
        // iterate through all the <option> elements and create UL
        options.each(function(){
            var disabled = '';
            var selectedClass = '';
            if($(this).attr('disabled')){
                disabled = 'disabled';
            }
            if($(this).text() == selected.text()){
                selectedClass = 'selected';
            }
            $('ul', parent).append('<li class="'+disabled+' '+selectedClass+'" data-value="'+$(this).val()+'">' + $(this).text() + '</li>');
        });

        source.change(function(){
        $('li.selected', parent).removeClass('selected');
            $('li[data-value='+source.val()+']', parent).addClass('selected');
            $('.jq-selected', parent).attr('data-value', source.val()).html(source.find('option:selected').text());
        });

        var dropdown = $('.jq-selectbox', parent);
        var list = $('ul', parent);
        dropdown.keydown(function(e){
            
            if(!dropdown.hasClass('open')){
                e.preventDefault();
                if(e.which === 40 || e.which === 38){
                    openSelect(dropdown);
                }
            }
            else{
                //ner
                if(e.which === 40){
                    e.preventDefault();
                    list.find('li.hover').nextAll('li').not('.disabled').first().addClass('hover');
                    if(list.find('.hover').length > 1){
                        list.find('.hover').first().removeClass('hover');
                    }
                }

                //upp
                if(e.which === 38){
                    e.preventDefault();
                    list.find('li.hover').prevAll('li').not('.disabled').first().addClass('hover');
                    if(list.find('.hover').length > 1){
                        list.find('.hover').last().removeClass('hover');
                    }
                }

                //enter / space
                if(e.which === 13 || e.which === 32){
                    selectValue(list);
                }
            }
        });
        dropdown.find('.jq-selected').click(function(){
            if(!dropdown.hasClass('open')){
                openSelect(dropdown);
            }
        });

        $('li', list).click(function(){
            if(!$(this).hasClass('disabled')){
                $('.selected', list).removeClass('selected');
                $(this).addClass('selected');
                selectValue(list);
            }else{
                dropdown.blur();
            }
        });

        dropdown.focusout(function(){
            dropdown.removeClass('open');
            $('li.hover', list).removeClass('hover');
        });

        $('li', parent).not('.disabled').hover(function(){
            $('li.hover', parent).removeClass('hover');
            $(this).addClass('hover');
        }, function(){
            $('li.hover', parent).removeClass('hover');
        }); 

        function selectValue(list){
            $('li.selected', list).removeClass('selected');
            var text = $('li.hover', list).addClass('selected').html();
            $('.jq-selected', dropdown).html(text);
            dropdown.removeClass('open');
            source.val($('li.hover', list).attr('data-value'));
        }
        function openSelect(dropdown){
            dropdown.addClass('open');
            if(!$('li.selected', list).length){
                $('li', list).not('.disabled').first().addClass('hover');
            }else{
                $('li.selected', list).addClass('hover');
            }
            var optionHeight = list.find('li').height();
            var focusedIndex = list.find('li').index(list.find('li.selected'));
            list.css('top', '-'+ (optionHeight * focusedIndex) +'px');
            if(list.offset().top < 0){
                list.css('top','-'+parent.offset().top+'px');
            }
        }
	
	});
}


$('.myselect').jQueryForm();

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console