jQuery: Highlight text

This helps us in highlighting text using jQuery and Regular Expression. It is fully optimized and performs so well. Regular expression played very well.

CSS Code:

<style type="text/css">
	.highlight {
		background:#F6FF00;}
</style>

HTML Code:

<p>Donec et the velit et metus auctor facilisis.</p>
<p>Vestibulum anthe ipsum velit in faucibus orci luctheus velit ultrices posuere cubilia Curae.</p>
<p>Class aptent taciti sociosqu ad litora torquent per conubia nosthera, velit inceptos himenaeos.</p>
<p>Sed at nisi vel turpis velit aliquet. Curabitheur in lacus eget thellus velit eleifend eu vel sapien. Quisque non leo est. Vestibulum velit interdum odio faucibus euismod. Phasthellus velit laoreet arcu. Nunc ac convallis dolor. Vivamus velit imperdiet turpis nec condimentum.</p>

jQuery Code:

<script type="text/javascript">
var textvalue = "velit";		
	$(function(){
		$('p:contains('+textvalue+')').each(function(){
			var regex = new RegExp(textvalue, "g");
			$(this).html( $(this).html().replace( regex ,"<span class='highlight'>"+textvalue+"</span>")); 
		});
	});
</script>

Thanks http://www.tripbase.com/code/highlight.html

03. August 2012 by Raju Sarvasiddi
Categories: jQuery | Tags: , , , | 15 comments

15 comments on “jQuery: Highlight text

  1. Kip Wurster on said:

    Awesome post! I will keep an on eye on your blog.

  2. Douglass Stanback on said:

    I simply want to say I am all new to blogs and certainly enjoyed your blog. More than likely I’m want to bookmark your blog . You really come with wonderful articles. Appreciate it for sharing your web site.

  3. male edge pro video on said:

    I’m no longer positive the place you’re getting your information, but great topic. I needs to spend some time finding out much more or working out more. Thanks for wonderful information I was in search of this info for my mission.

  4. High PR Backlink Pyramid on said:

    Wow that was odd. I just wrote an incredibly long comment but after I clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Regardless, just wanted to say fantastic blog!

  5. Willard Rogstad on said:

    more essential for all kinds of online web Form Designers.
    it’s my seems.
    yours?

  6. Royce Dykstra on said:

    Validation is huge when it comes to forms. If certain elements are required and there is really a user error, the error should post relative on the field and be obvious. It’s happened so many times where I truly really have to search the web page for what I did incorrectly on a form. Many thanks for your short article.

  7. Mathew Cypher on said:

    I just want to tell you that I am just all new to weblog and actually loved this web site. Almost certainly I’m planning to bookmark your blog post . You actually have fantastic articles and reviews. Bless you for sharing your blog.

  8. Trent Avendano on said:

    After study just a few of the blog posts in your website now, and I really like your approach of blogging. I bookmarked it to my bookmark website record and shall be checking again soon. Pls try my site as well and let me know what you think.

  9. wallpaper on said:

    Attractive part of content. I just stumbled upon your weblog and in accession capital to assert that I get in fact loved account your weblog posts. Anyway I’ll be subscribing on your augment or even I success you access consistently rapidly.

    • Hello! I’m at work browsing your blog from my new iponhe 3gs! Just wanted to say I love reading through your blog and look forward to all your posts! Keep up the great work!

  10. Replica rolex on said:

    Itˇs really a nice and useful piece of info. Iˇm glad that you simply shared this useful information with us. Please keep us up to date like this. Thank you for sharing.

    • 说:I think what you posted made a bunch of sense. But, what about this? what if you added a litlte information? I am not suggesting your content isn’t good, however what if you added a post title that makes people desire more? You ought to look at Yahoo’s home page and note how they create post headlines to grab viewers to open the links. You might add a related video or a related picture or two to get people interested about everything’ve got to say. Just my opinion, it might bring your website a litlte bit more interesting.

  11. supra shoes on said:

    As a Newbie, I am always searching online for articles that can aid me. Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *

*

HTML tags are not allowed.