how to search and highlight text in a webpage....

Posted by Premkumar.ng under JavaScript on 1/19/2012 | Points: 10 | Views : 2908 | Status : [Member] | Replies : 3
hi frnd...
this is prem here....i need your help to do this..Now am working on webpage...i need to search and highlight text content present in the webpage through the textbox not through the text searchPrompt instead of that i have one search box and search button....by onclick it should search and highlight the text in the text in the webpage...

please help me...its very urgent..

Thanks in advance..

Prem kumar.A




Responses

Posted by: Hemanthlaxmi on: 1/20/2012 [Member] Starter | Points: 25

Up
0
Down
jQuery has the contains method. Here's a snippet for you:

<script type="text/javascript">
$(function() {
var foundin = $('*:contains("I am a simple string")');
});
</script>

The selector above selects any element that contains the target string. The foundin will be a jQuery object that contains any matched element. See the API information at: http://docs.jquery.com/Selectors/contains#text

One thing to note with the '*' wildcard is that you'll get all elements, including your html an body elements, which you probably don't want. That's why most of the examples at jQuery and other places use $('div:contains("I am a simple string")')


If this helps you .
Please "Mark as Answer"

Premkumar.ng, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Premkumar.ng on: 1/20/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks for ur answer hema...
Am having the search option in my website.......if i search any word trough that search option it should search and highlight the text which is present in the webpage not from database or from any other server...if u have any code to do this means...pls post it here.....

once again thanks for ur reply...

keep posting..
Thanks & Regards
Premkumar.A

Premkumar.ng, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hemanthlaxmi on: 1/20/2012 [Member] Starter | Points: 25

Up
0
Down
If that help you.
Please "Mark as Answer".

If this helps you .
Please "Mark as Answer"

Premkumar.ng, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response