JSFiddle - React, Tailwind, and code Playground
HTML
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.js"></script>
<body onload="myFunction1()">
<br>
<br>
<div class="row">
<div class="column left" style="background-color:White;"></div>
<div class="column right" style="background-color:#bbb;">
<form id="myForm" onsubmit='return onSubmit(this)'>
Find:
<input type="text" class="demo1" id="myInput" align="center" onkeyup="myFunction()" placeholder="Search here...">
<button id="clear" onclick="document.getElementById('myInput').value = ''"> Clear </button>
</form>
<br>
<br>
<ul id="demo">
15 words total
</ul>
<br>
<br>
<div style="width:100%;height:180px;overflow:scroll;padding:5px;color:#714D03;scrollbar-base-color:#DEBB07;">
<ul id="myUL" class="demo">
</ul>
</div>
</div>
</div>
<script>
$('#demo').on("mouseenter", "li", function() {
$(this).find("span").show();
})
$('#demo').on("mouseout", "li", function() {
$(this).find("span").hide();
})
</script>
CSS
* {
box-sizing: border-box;
}
#myInput {
width: 50%;
font-size: 14px;
padding: 8px 10px 8px 5px;
border: 1px solid #ddd;
margin-bottom: 12px;
margin-top: 20px;
}
#clear {
margin-left: 20px;
margin-top: 40px;
font-size: 14px;
margin-right: 50px;
padding: 4px 4px 4px 4px;
}
#myUL {
list-style-type: none;
padding: 0;
margin: 0;
}
#myUL li a {
border: 1px solid #ddd;
margin-top: -1px;
/* Prevent double borders */
background-color: #f6f6f6;
padding: 8px;
text-decoration: none;
font-size: 16px;
color: black;
display: block;
width: 100%;
}
#myUL li a:hover:not(.header) {
background-color: #eee;
}
body {
margin: 0;
}
.column {
float: left;
margin-top: 50px;
padding: 10px;
height: 550px;
}
.left {
width: 20%;
}
.right {
width: 60%;
}
.row:after {
content: "";
display: table;
clear: both;
}
ul.demo {
display: inline-block;
border-bottom: 1px dotted black;
}
ul.demo li {
position: right;
}
.tool-tip {
display: none;
width: 100px;
background-color: white;
color: #fff;
text-align: center;
border-radius: 2px;
position: absolute;
z-index: 1;
color: black;
}
.highlight {
font-weight: bold;
color: red;
}
li em {
background: #ff6;
font-weight: bold;
font-style: normal;
}
JavaScript
var persons = [{
firstname: "Malcom",
lastname: "Reynolds",
id: 1
}, {
firstname: "Kaylee",
lastname: "Frye",
id: 2
}, {
firstname: "Jayne",
lastname: "Cobb",
id: 3
}, {
firstname: "Mal",
lastname: "Rlds",
id: 4
}, {
firstname: "ylee",
lastname: "ye",
id: 5
}, {
firstname: "yne",
lastname: "Cb",
id: 6
}, {
firstname: "Mal",
lastname: "Rolds",
id: 7
}, {
firstname: "lee",
lastname: "Fryedwwwwd",
id: 8
}, {
firstname: "Jay",
lastname: "bdwe",
id: 9
}, {
firstname: "Maljh",
lastname: "Rolds",
id: 10
}, {
firstname: "ljyyu",
lastname: "jhjFryed",
id: 11
}, {
firstname: "ryJay",
lastname: "jkmCdwe",
id: 12
}, {
firstname: "yuryMal",
lastname: "jhkhRolds",
id: 13
}, {
firstname: "rtulee",
lastname: "Frwwd",
id: 14
}, {
firstname: "ryuyJay",
lastname: "Cryyobbdwe",
id: 15
}];
function getFullName(item, index) {
return "<li>" + item.firstname + "<span class='tool-tip'>" + item.lastname + "</span> " + item.id + "</li>";
}
var getFullNameForHighlighting = function(searchText) {
return function(item, index) {
var index = item.firstname.toUpperCase().indexOf(searchText.toUpperCase())+searchText.length;
console.log(index)
return "<li>" + "<span class='highlight'>"+searchText + "</span>" +item.firstname.substring(index) + "<span class='tool-tip'>" + item.lastname + "</span> " + item.id + "</li>";
}
};
function myFunction1(){
document.getElementById("demo").innerHTML = persons.map(getFullName);
}
function myFunction() {
var input, filter, ul, li, a, i, count = 0;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
var longWords = persons.filter(function(person) {
return person.firstname.toUpperCase().indexOf(filter) > -1
});
var message = "Result:" + longWords.length + " words containing '" + input.value;
document.getElementById("demo").innerHTML = message;
ul = document.getElementById("myUL");
...