Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] Take tooltip content from the element attributes
13th March, 21:53
Post: #1
Take tooltip content from the element attributes
Hi,

Great work! I am wondering, if there a simple way to get tooltip content from the element attribute, ex "title"?

The problem is that when you have a lot of tooltips on the page, it is easier to put each tooltip content inside its corresponding element and initialize all the tooltips once.

it could be a great feature, unless i am missing something and it could be done with the current version.

Andy
Find all posts by this user
Quote this message in a reply
13th March, 23:05
Post: #2
[Solved] Take tooltip content from the element attributes
Hi AndyG,

This is indeed possible with the current version of qTip, but it means sacrificing validation if you plan to use non-standard attribute tags. Heres a quick example of how to accomplish this task by using the "tooltip" attribute on your elements:

First, define the elements
JS Code
<div id="test" tooltip="this my my tooltip content">Hover over me</div>
<div id="test2" tooltip="this my my tooltip content, it's similar to the one above">Hover over me too!</div>


Now here's the code to create the tooltips:
JS Code
$('[tooltip]').each(function() // Select all elements with the "tooltip" attribute
{
   $(this).qtip({ content: $(this).attr('tooltip') }); // Retrieve the tooltip attribute value from the current element
});


And there we have it. Tooltips with content based on values of attributes within the HTML element itself.

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
17th March, 11:42
Post: #3
Take tooltip content from the element attributes
Thanks, Craig! It is working fine. One of the problem what I am experiencing is that qtip creates static divs rather than doing it on-fly. Just imagin the dynamic output of some listings, where each would require 4-5 icons with tooltips. No-brainer, 100 listings would generate 100 tooltip constructions (wrapper +2 internal divs). I am trying to optimize it somehow not to overload the page...
Find all posts by this user
Quote this message in a reply
17th March, 14:52
Post: #4
Take tooltip content from the element attributes
You bring up a very good point AndyG. I guess what your suggesting is creating the tooltip on the show event, rather than pre-rendering them on the page? This sounds like a very nice option that could be implemented quite easily. What do you think? Is this what you meant?

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
17th March, 20:26
Post: #5
Take tooltip content from the element attributes
craig Wrote:You bring up a very good point AndyG. I guess what your suggesting is creating the tooltip on the show event, rather than pre-rendering them on the page? This sounds like a very nice option that could be implemented quite easily. What do you think? Is this what you meant?

Yes, this is exactly what i was talking about. It could be a good solution for pages with hundreds of tooltips. I have been using http://www.walterzorn.com/tooltip/tooltip_e.htm all the time, but wanted to utilize jquery since it is the core library for the project.

Here is another point as why tooltips on mouseover would be better. I am generating the content via ajax, so qtips cannot be pre-rendered, but I have to call it explicitly every time after the page generated. Next, I am using jquery pagination, which creates another set of pages from the initial ajax content. So, I have to destroy and recreate qtips for each page. Quite a big headache for just tooltips.
Find all posts by this user
Quote this message in a reply
17th March, 22:05
Post: #6
Take tooltip content from the element attributes
I'm impressed with the suggestion AndyG, and I'll definitely be including this as, at the very least, an option within the next beta.

If you have any other feature suggestions make sure to get posting!

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
21st March, 12:33
Post: #7
Take tooltip content from the element attributes
This is now implemented as of beta3.

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
21st March, 13:47
Post: #8
Take tooltip content from the element attributes
I also posted another alternative on doing this here:

http://craigsworks.com/projects/qtip/for.../143/#p143

It uses the api.beforeShow callback to updating the content. This can also be used to dynamically update the tooltip based up the state of the target (such as a specific class being present.)
Find all posts by this user
Quote this message in a reply
1st April, 22:26
Post: #9
Take tooltip content from the element attributes
This post has helped tremendously. Thanks!
Find all posts by this user
Quote this message in a reply
2nd April, 10:50
Post: #10
Take tooltip content from the element attributes
Hello!

I'm also new to building pages with dynamic javascript. I have a question regarding stylization. I haven't been able to effectively add styles to the following script:

JS Code
<script type="text/javascript">
   $('[tooltip]').each(function() // Select all elements with the "tooltip" attribute
   {
   $(this).qtip({ content: $(this).attr('tooltip') }); // Retrieve the tooltip attribute value from the current element
   });
</script>


Where do I add the styles in? I've tried a number of different combinations using tutorial code, but something isn't working quite right. Here's the context--when the user is hovering over an image that will then, upon clicking on it, display an .mp4 using the shadowbox.js player, I want the tooltip to display information written by the filmmaker with, also, a title of the film.

Please assist!

You're amazing.
Find all posts by this user
Quote this message in a reply
3rd April, 02:39
Post: #11
Take tooltip content from the element attributes
Love qTip!

I'm new to it, and I'm having a little trouble implementing the concept in this thread.

My test code:
JS Code
<script type="text/javascript">
   $('.flag').qtip({
      content: {text: $(this).attr('id'),
            title: { 
              text: 'About Me', 
              button: 'Close'
            } },
      show: {solo: true, ready: false, when: 'mouseover'},
      hide: { when: 'blur', fixed: true }
   })
</script>


Does not seem to show the id that is set for the element. It comes through as blank, even though the attribute is:
JS Code
<img src="/images/circle.png" id="test_content_here" class="flag">


Can you help me see what I am missing?
Find all posts by this user
Quote this message in a reply
3rd April, 11:55
Post: #12
Take tooltip content from the element attributes
You need to use the each() method if your retrieving attributes etc. from each element within the selector:

JS Code
<script type="text/javascript">
   $('.flag').each(function(){
      $(this).qtip({
         content: {text: $(this).attr('id'),
               title: { 
                 text: 'About Me', 
                 button: 'Close'
               } },
         show: {solo: true, ready: false, when: 'mouseover'},
         hide: { when: 'blur', fixed: true }
      });
   });
</script>

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
3rd April, 18:20
Post: #13
Take tooltip content from the element attributes
Thanks for the quick response! that fixed it
Find all posts by this user
Quote this message in a reply
10th April, 19:34
Post: #14
Take tooltip content from the element attributes
Craig, I just wanted to thank you for this. It's super handy and easily combines with other tooltip styling elements.

For those interested, here's how I'm doing my images inside a dialog box:

For the HTML, I'm using
JS Code
<a href="/products/index.cfm" tooltip="<img src='images/menuhovers/cornice.jpg' />">


And here's my .js

JS Code
$('[tooltip]').each(function() // Select all elements with the "tooltip" attribute
{
   $(this).qtip({ content: $(this).attr('tooltip'),
     position: {
      corner: {
         target: 'topRight',
         tooltip: 'bottomLeft'
      }
   },
        style: { 
        border: {
         width: 1,
         radius: 3,
         color: '#AEC18A'
        },
      padding: 0,
      tip: { // Now an object instead of a string
         corner: 'bottomLeft', // We declare our corner within the object using the corner sub-option
         color: '#AEC18A',
         size: {
            x: 20, // Be careful that the x and y values refer to coordinates on screen, not height or width.
            y : 8 // Depending on which corner your tooltip is at, x and y could mean either height or width!
         }
  },
      width: 106
}
 
                              }); // Retrieve the tooltip attribute value from the current element
});


Not necessarily the prettiest, but it works and is pretty easy to understand/change.
Find all posts by this user
Quote this message in a reply
22nd June, 03:00
Post: #15
Take tooltip content from the element attributes
i nealry posted a big question here, but instead ill be posting a solution Smile

i was having some trouble trying to retreive a url address to display in my tooltip instead of just some static content. even though it partially worked (displayed the url address instead) i needed to use an alternative attribute tag as my page was coded in asp and ToolTip is a reserved attribute which was causing the problem.

hope that helps someone else out in the future.
Find all posts by this user
Quote this message in a reply
19th October, 08:06
Post: #16
RE: Take tooltip content from the element attributes
from where i can have beta 3 ?
and thanks for the informative posts in the thread .

chicago real estate
Find all posts by this user
Quote this message in a reply
20th December, 07:08
Post: #17
RE: Take tooltip content from the element attributes
When I try this code, I get bottom scroll bar instead of the tip.


(13th March 23:05)Craig Wrote:  Hi AndyG,

This is indeed possible with the current version of qTip, but it means sacrificing validation if you plan to use non-standard attribute tags. Heres a quick example of how to accomplish this task by using the "tooltip" attribute on your elements:

First, define the elements
JS Code
<div id="test" tooltip="this my my tooltip content">Hover over me</div>
<div id="test2" tooltip="this my my tooltip content, it's similar to the one above">Hover over me too!</div>


Now here's the code to create the tooltips:
JS Code
$('[tooltip]').each(function() // Select all elements with the "tooltip" attribute
{
   $(this).qtip({ content: $(this).attr('tooltip') }); // Retrieve the tooltip attribute value from the current element
});


And there we have it. Tooltips with content based on values of attributes within the HTML element itself.
Find all posts by this user
Quote this message in a reply
31st January, 07:14
Post: #18
RE: Take tooltip content from the element attributes
I just wanna share my experience with qTip on IE.
some times when i use lots of that tips it runs out of sources(it seems so) and page gets so slow.
so I used
[
onHide:function()
{
qtip('destroy')
}
]
to solve the problem and it worked.
wish it's useful
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  [Solved] how to set an ID for the qtip generated element buntu 8 3,238 16th February 09:53
Last Post: johannapelkonen
  [Solved] Getting tooltip to appear on different element with the same class name andrewhoule 5 1,455 25th August 18:17
Last Post: Craig
  How customize content modal tooltip? dannythegreat 7 3,207 25th December 16:49
Last Post: Spoonless Eddie
  Style by element class, content by element id teeks 14 5,666 15th November 21:35
Last Post: garbledygook
  [Solved] Using Complex HTML as Tooltip Content sylvia 1 2,430 3rd November 02:07
Last Post: Craig
  programatically show tip in different element jorfermo 8 2,442 31st March 12:20
Last Post: jorfermo
  Use hovered element's own HTML for qtip content discern 2 3,730 10th December 13:52
Last Post: discern
  Accessing cloned tooltip content root66 2 1,404 29th June 16:23
Last Post: Craig



User(s) browsing this thread: 1 Guest(s)