In this post we will discuss how we can create a tool tip by using JQuery. Here we are not going to use any plugin to create tool tip. We will use only jQuery and html table for this demo. I hope you will like this.
Background
Recently, I was going through a situation to create a tool tip for my grid. As we all know there are plenty of plugins available for the tool tip generation. But I was not ready to go with any plugin for this. So I thought of creating it manually.
Please see this article in my blog
here
Using the code
Firstly, we will create a page and an html table.
Now if you run your page and you can see the table.
Create Tooltip Without Any Plugins
Now we will add our script to the page.
- <script>
- $(document).on('mouseover', '.table td', function () {
- $(this).attr('title', $(this).text());
- });
- </script>
Here what we are doing is, we are just appending the title attribute for the td element in the mouseover event. Now run your page, and see our tool tip works perfectly.
Create Tooltip Without Any Plugin
We have done it finally.
Complete Code
- <!DOCTYPE html>
- <html>
- <head>
- <title>Create Tooltip Without Any Plugins</title>
- <script src="jquery-2.0.2.min.js"></script>
- <script>
- $(document).on('mouseover', '.table td', function () {
- $(this).attr('title', $(this).text());
- });
- </script>
- </head>
- <body>
- <table class="table" border="1" style="width: 100%">
- <tr>
- <td>Sibi</td>
- <td>Ajay</td>
- <td>50</td>
- </tr>
- <tr>
- <td>Ansu</td>
- <td>Akhil</td>
- <td>94</td>
- </tr>
- <tr>
- <td>Shanto</td>
- <td>Libin</td>
- <td>80</td>
- </tr>
- </table>
- </body>
- </html>
Conclusion
Did I miss anything that you may think which is needed?Have you ever faced this issue in your programming life? I hope you liked this article. Please share me your valuable suggestions and feedback.
Your turn. What do you think?
A blog isn’t a blog without comments, but do try to stay on topic. If you have a questions, the please mention it in the comments section.