How to make a live page search among all links in native JS?
-
Hello everyone, I solve a problem, I am learning to develop in JS, you need to create a search, the result in the form of a drop-down list and highlight the found elements.
While I was able to implement the search for the desired element and hide the rest. Tell me how to solve the problem completely.
my codeJavaScript Owen Frazier, May 6, 2020 -
learning to develop in JS
tell me how to solve the problem completely
Great start, keep it up. Seriously, you've written 10 lines of code and you're done with ideas?
But it's not difficult to tell: you go to the wiki, use the search, press f12 and see how the display is implemented there. You copy. Truncated.Anonymous -
Next, to highlight you need:
- get length
let pos = value.length;
- in your
forEach
loop, take a substring from elem from 0 to pos in a match condition and write it to the variable
- wrap the value of this variable in
span
- take a substring from elem from pos to the end of the line and write to the variable
- add these two variables and assign elem
- add to css
a & gt; span {background: yellow}
Anonymous - get length
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!