Search the Community
Showing results for tags 'replace()'.
-
So,I'am Creating An Internal Search Engine Which Can Be Used To Search For A Specific Word In The Page You're Browsing. This Engine Makes The Background Color Is Yellow For The Word You're Searching. <!--Taken From W3Schools.com--> <p> The display property sets or returns the element's display type. Elements in HTML are mostly "inline" or "block" elements: An inline element has floating content on its left and right side. A block element fills the entire line, and nothing can be displayed on its left or right side. </p> <p> The display property also allows the author to show or hide an element. It is similar to the visibility property. However, if you set display:none, it hides the entire element, while visibility:hidden means that the contents of the element will be invisible, but the element stays in its original position and size. Tip: If an element is a block element, its display type can also be changed with the float property. </p> <script> var i; function searchFor(keyword) { for (i=0;i<document.querySelectorAll("p").length;i++) { document.querySelectorAll("p").innerHTML=document.querySelectorAll("p").innerHTML.replace(/keyword/gi,"<span style='background-color:yellow;'>"+keyword+"</span>"); } searchFor("display"); </script> How Can I Make It Possible To Pass A String As A Parameter To The searchFor() Function?