Search for text with javascript inside a div class -


I want to create a script in which I can automatically search for a certain string (a text box or anything No, I want to press a button and it searches for the word "bear", inside the example) using "document.getElementByClassName" ... something like "brain" content "or" included " It seems to be going for things, but I failed a lot .. would anyone have me The Dahrn can help you with the code?

Thank you in advance :)

I get the element easily by class name And suggest using jquery to identify people with search values. Something like this:

  var searchValue = "bears"; $ ("Category"). Each (function () {if ($ (this) .html (). IndexOf (searchValue)> gt; -1) {// match has been made}});  

If you are limited to vanilla javascript, here's an example:

  var els = document.getElementsByClassName ("ClassName"); Var search value = "bear"; For (var i = 0; i & lt; els.length; i ++) {if (Els [i]. WinnerHTML.indexOf (searchValue)> 1) {// match has been made}}  

I think that what you actually see is a comparator String.indexOf (SearchValue) & gt; -1, , will determine if the content of the element is a match for the string you are looking for. Note that this is case-sensitive.


Comments