const tags = [
'Alaska',
'Asia / Far East',
'Baltic Capitals / Northern Europe',
'Canary Islands',
'Caribbean',
'Cruise from Ireland',
'Dubai & The Emirates',
'Grand Voyages / Repositioning Cruises',
'Mediterranean',
'Northern Lights',
'Norwegian Fjords',
'South America',
'Transatlantic',
'UK & Ireland',
];
const startTyping = "Start typing...";
const inputDiv = document.getElementById('MyText');
const suggestionList = document.getElementById('autocomplete-list');
let currentFocus = -1;
// Function to get caret position
function getCaretCoordinates() {
const selection = window.getSelection();
if (selection.rangeCount === 0) return { x: 0, y: 0 };
const range = selection.getRangeAt(0).cloneRange();
range.collapse(false);
const rect = range.getBoundingClientRect();
return { x: rect.left, y: rect.bottom };
}
// Function to place caret at the end
function placeCaretAtEnd(el) {
el.focus();
if (typeof window.getSelection != "undefined" && typeof document.createRange != "undefined") {
const range = document.createRange();
range.selectNodeContents(el);
range.collapse(false);
const sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
}
}
// Function to close the suggestion list
function closeSuggestionList() {
suggestionList.innerHTML = '';
suggestionList.hidden = true;
inputDiv.setAttribute('aria-expanded', 'false');
currentFocus = -1;
}
// Function to add active class to suggestion
function addActive(items) {
if (!items) return false;
removeActive(items);
if (currentFocus >= items.length) currentFocus = 0;
if (currentFocus < 0) currentFocus = items.length - 1;
items[currentFocus].classList.add("active");
inputDiv.setAttribute('aria-activedescendant', items[currentFocus].id);
}
// Function to remove active class from suggestions
function removeActive(items) {
for (let item of items) {
item.classList.remove("active");
}
}
// Function to insert...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.