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


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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


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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <h1>jQuery Autocomplete</h1>
<input type="text" name="country" id="autocomplete" placeholder="Type a country here"/>
<p id="selection-ajax"></p>

<br />
<br />
<hr />
<p style="text-align:left;">If you find this demo useful, please consider <a href="" target="_blank">donating $1 dollar</a> (secure PayPal link) for a coffee or purchasing one of my songs from <a href="" target="_blank"></a> or <a href="" target="_blank"></a> for only 0.99 cents each.</p>
<p style="text-align:left;">Rob uses and recommends <a href="" target="_blank">MochaHost</a>, which provides Web Hosting for as low as $1.95 per month, as well as unlimited emails and disk space!</p>


  text-align: center;
  width: 300px;
  padding: 7px;
.ui-widget-content {
  text-align: left;

.autocomplete-suggestions { text-align: left; border: 1px solid #999; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; background: #FFF; overflow: auto; }
.autocomplete-suggestion { padding: 5px 5px; white-space: nowrap; overflow: hidden; cursor: pointer;}
.autocomplete-selected { background: #F0F0F0; }
.autocomplete-suggestions strong { font-weight: normal; color: #3399FF; }
.autocomplete-group { padding: 2px 5px; }
.autocomplete-group strong { display: block; border-bottom: 1px solid #000; }

.ui-autocomplete .highlight { 
  color: blue; 



                // Initialize ajax autocomplete:
var aCountries = [],
    cache      = {};
    // serviceUrl: '/autosuggest/service/url',
    delay: 500,
    minLength: 3, 
    create: function( event, ui ) {
      $.ajax( {
        url: "",
        dataType: "text",
        success: function( data ) {
          aCountries = data.split('\n').map(function(currentValue, index, arr) { 
            var labelValuePair = currentValue.split(':');
            return {
              label: labelValuePair[1],
              value: labelValuePair[0]
 		source: function(request, response) { 
      var term = request.term.toLowerCase();
      if ( !(term in cache) ) {
        console.log('Storing in cache...');
        var matcher = new RegExp("\\b" + $.ui.autocomplete.escapeRegex(term), "i");
        cache[term] = aCountries.filter(function(country) {
          return matcher.test(country.label);
      response( cache[term] );
    select: function(event, ui) {
        $('#selection-ajax').html( 'You selected: ' 
                                 + ui.item.value + ', ' + ui.item.label);
    focus: function(event, ui) {
}).on('keyup', function(event) {
  if ($( == 0) $('#selection-ajax').html(''); 
}).data('ui-autocomplete')._renderItem = function( ul, item ) {
  //thanks to Salman Arshad  
  var $div = $("<div></div>").text(item.label), 
      searchText  = $.trim(this.term).toLowerCase(), 
      currentNode = $div.get(0).firstChild, 
      matchIndex, newTextNode, newSpanNode; 
  while ((matchIndex = >= 0) { 
    newTextNode = currentNode.splitText(matchIndex); 
    currentNode = newTextNode.splitText(searchText.length); 
    newSpanNode = document.createElement("span"); 
    newSpanNode.className = "highlight"; 
    currentNode.parentNode.insertBefore(newSpanNode, currentNode); 

  return $("<li></li>").append($div).appendTo(ul);