text search in javascript? -


I have a page with more than 200 links from this type of formatting.

  & lt; H1 & gt; & Lt; A href = "somelink" & gt; Soumilak & lt; / A & gt; Some text that interprets the meaning of the link & lt; / H1>  

Now, to make this link look a little easier, I've put a search box.

My requirement is to search through this tag and the links that are relevant to the search box and hide the rest of the link

How to do this in JavaScript? (I know the basic javascript / jquery stuff but how to search full text?) I do not need sorting according to the relevant, just enough to hide filter and show off is enough

Hope you find it useful. This is probably not elegant or most efficient but it gives you more than one search term and partial matches (which can or can not be done). The way I made it, when you click on the search button, it will hide all the other elements that match all your search terms, but you can modify it which you want with the elements of the result. I do not recommend using it properly, but hopefully it will give you a point of reference that how you want to implement your own (if you are in addition to quick search C. choose to go with the resolution)

  & lt; Html & gt; & Lt; Top & gt; & Lt; Script src = "http://code.jquery.com/jquery-latest.min.js" & gt; & Lt; / Script & gt; & Lt; Script type = 'text / javascript' language = 'javascript' & gt; $ (Document) .ready (function () {var links = new Array (); $ ("h1"). Each (function (index, element) {links.push ({text: $ (this) .text () Click on (function () {var query = $ ("# searchbox"). Val (); var queryTerms = query.split ('') ; Var results = new array (); for (var i = 0; i & lt; queryTerms.length; i ++) {for (var j = 0; j & lt; links.length; j ++) { If (link [j] .text .indexOf (query items [i]) gt; 1) {results.push (link [j] element);}}} $ ("h1"). Each (function (index , Element) {this.style.display = 'none';}); (var i = 0; i & lt; result; tall; i ++) {result [i] .style.display = 'block ';}});}); & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; P & gt; & Lt; Input id = "search box" type = "text" / & gt; & Lt; Input type = "button" id = "searchButton" value = "search" /> & Lt; / P & gt; & Lt; H1 & gt; & Lt; A href = "somelink" & gt; Sommail 1 & lt; / A & gt; Asdf & lt; / H1> & Lt; H1 & gt; & Lt; A href = "somelink" & gt; Sommail 2 & lt; / A & gt; Ssss & lt; / H1> & Lt; H1 & gt; & Lt; A href = "somelink" & gt; Somalink 3 & lt; / A & gt; 3333 & lt; / H1> & Lt; H1 & gt; & Lt; A href = "somelink" & gt; Somalink 4 & lt; / A & gt; 232323 & lt; / H1> & Lt; H1 & gt; & Lt; A href = "somelink" & gt; Somilin 5 & lt; / A & gt; Fffff & lt; / H1> & Lt; / Body & gt; & Lt; / Html & gt;  

Comments