Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thegulshankumar/704866966be96c2f338d9b21d0684f7c to your computer and use it in GitHub Desktop.
Save thegulshankumar/704866966be96c2f338d9b21d0684f7c to your computer and use it in GitHub Desktop.
Display Search Results Query in Heading and Title
<script>
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const searchTerm = urlParams.get('q');
if (searchTerm) {
const heading = document.querySelector('h1');
const title = document.querySelector('title');
heading.textContent = `Search Results for ${searchTerm}`;
title.textContent = `Search Results for ${searchTerm}`;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment