connectseekers.com

Friday, 21 October 2016

Highlight Search Text Using jQuery

10/21/2016 - By Pranav Singh 0

This article will show you how you can highlight search text using jquery present in a div control or in a span control in your asp.net, html application.

So for this article first we will download the jquery library from given link.

http://www.jqueryscript.net/text/Smart-Text-Highlighting-Plugin-with-jQuery-jQuiteLight.html

Now we will add the below mention library reference into the header of the page.

  <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="jquitelight.min.js"></script>

After this we will add the below mention function

  function OnchangeHeilight() {
            var data = $("#txtData").val();
            $("span").removeClass("marked-text");
            $("#txtContent").mark([data]);
        }

In above code I have first cleared the highlighted text and after that highlight the searched text.
Now use the below css to highlight the text.

  .marked-text {
            background-color: yellow;
            font-weight: bold;
            padding: 0 5px;
            color: #000;
            font-weight: 300;
        }

Now we have done check the complete code.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Highlight Search Text Using jQuery</title>
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="jquitelight.min.js"></script>
    <script>
        function OnchangeHeilight() {
            var data = $("#txtData").val();
            $("span").removeClass("marked-text");
            $("#txtContent").mark([data]);
        }
    </script>
    <style>
        .marked-text {
            background-color: yellow;
            font-weight: bold;
            padding: 0 5px;
            color: #000;
            font-weight: 300;
        }
    </style>
</head>
<body>
    search Text: <input type="text" id="txtData" onchange="javascript: OnchangeHeilight();" />
    <br /><br />
    <div id="txtContent" style="width:300px;border:1px solid black;">
        This article will show you how you can search and highlight the text in a gridview control in asp.net using c#. This i have shown on button click event.
    </div>
</body>
</html>

Now we have done run the application to check the output.



About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top