Created
February 19, 2017 18:47
-
-
Save zaclittleberry/326c460bcf14e1fb29a1d74baab969cb to your computer and use it in GitHub Desktop.
A little script demonstrating a search form that will scan elements on a page (currently anchors) and highlight them if they contain the search phrase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Highlighter</title> | |
<style> | |
.highlight {color: orange;} | |
a {color: blue; text-decoration: none;} | |
</style> | |
</head> | |
<body> | |
<form id="form" onsubmit="highlight(e)"> | |
<input type="text" id="textbox"/> | |
<input type="submit" value="submit"> | |
</form> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> | |
<script> | |
$('#form').submit(function(e){ | |
e.preventDefault(); | |
highlight(); | |
}) | |
function highlight(){ | |
console.log('working'); | |
$('#content a').removeClass('highlight'); | |
var search = $('#textbox').val(); | |
$('#content a:contains('+search+')').addClass('highlight'); | |
} | |
</script> | |
<div id="content"> | |
<a href="#">one</a> | |
<a href="#">two</a> | |
<a href="#">three</a> | |
<a href="#">search</a> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment