Tutorials
Search HTML page content using Javascript
Written by Andy Sharman Saturday, 06 June 2009 17:17
I was helping a friend on a forum recently, and found quite a nifty tool to help him have a huge downloadable page, and keep the search functionality, and it was by using Javascript to make a Search function loop through the HTML elements within the page and detect the search results and highlight them using CSS. Anyway enough blabber, here is the code:The Javascript/HTML shows you what you need to put in place for the HTML form when posting (note this is NOT HTML strict valid - only Transitional).
Here is the CSS I used to highlight the text found by the Javascript Search functions.
Also here are the links to the two Javascript files you will need for the above to work.
You will need jQuery, and a file using the jQuery library jquery.highlight.js
All content is copyrighted to udjamaflip.com 2009-2010, All rights reserved.
Comments
I think a conditional statement should be placed in the code, that will fix the issue.
Code:
javascript:if (document.getElementById(\'text\').value.length > 0) { void($(\'body\').removeHighlight().highlight(document.getElementById(\'text\').value)); } return false;Great code snippet anyways, thank you!
RSS feed for comments to this post.