Skip to content

Commit

Permalink
Merge pull request #29 from rchillard/20-fix-search-input
Browse files Browse the repository at this point in the history
Fix issue with search input on reference page not working on major browsers
  • Loading branch information
rchillard authored Apr 8, 2023
2 parents 0a54178 + aaf2559 commit e7253f8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h1>Reference HTML Elements</h1>
<h2>Search</h2>
<form>
<label>By element
<input list="elementList" placeholder="e.g. div" />
<input id="searchInput" list="elementList" placeholder="e.g. div" />
<!-- See bottom of page for elementList -->
</label>
<input type="submit" value="Search">
Expand Down Expand Up @@ -3965,8 +3965,11 @@ <h4>
search.addEventListener('select', goAnchor);
search.addEventListener('submit', goAnchor);

function goAnchor(event) {
var targetAnchor = document.getElementById(event.target.value).offsetTop;
var input = document.getElementById('searchInput');

function goAnchor(e) {
e.preventDefault();
var targetAnchor = document.getElementById(input.value).offsetTop;
window.scrollTo(0, targetAnchor);
}
</script>
Expand Down

0 comments on commit e7253f8

Please sign in to comment.