i try to make a instant search on a page which shows the user all the anchor links related to value of the search input field. The code works fine accept of the amount of links which begins with an a. My code outputs only one link with an a instead of all links which begins with an a. I hope someone can help me.
Attached my HTML/jquery code
$(document).ready(function(){
$("#output_result").css("display", "none");
$("#output_result").val("");
$('#search').keyup(function(){
$("#output_result").css("display", "block");
var searchedText = $(this).val();
var result = $("td.myClass:contains('"+searchedText+"')").html();
$("#output_result").html(result);
console.log(result);
if( $(this).val().length === 0){
$("#output_result").css("display", "none");
$("#output_result").val("");
}else {
$("#output_result").css("display", "block");
}
});
});
div#output_result {
border: solid 1px black;
width: 500px;
padding: 30px;
background: lightgray;
}
<!DOCTYPE html>
<html>
<head>
<title>MySearch</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<input type="text" id="search" placeholder="suche nach Standard"/>
<div id="output_result"></div>
<br/>
<table>
<tr>
<td class="myClass"><a href="custom_link_1" target="_blank">apple</a></td>
</tr>
<tr>
<td class="myClass"><a href="custom_link_2" target="_blank">ananas</a></td>
</tr>
<tr>
<td class="myClass"><a href="custom_link_3" target="_blank">anchovi</a></td>
</tr>
<tr><td class="myClass"><a href="custom_link_4" target="_blank">banana</a></td></tr>
</table>
</body>
</html>