Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use hovered element's own HTML for qtip content
9th December, 20:11
Post: #1
Use hovered element's own HTML for qtip content
I have several span tags which look similar to tds in a table. They have a set width and overflow: hidden in the CSS. I wanted to avoid sending a title attribute along to save bandwidth, because it would be a duplicate of the span's content. For example, instead of...

JS Code
<span class="x" title="foo...">foo...</span>


...I wanted to send...

JS Code
<span class="x">foo...</span>


...which, in many cases, would reduce sent data by about 40%. I thought I could do something like...

JS Code
$("span.x").qtip({
  content: {
    text: function(){
      $(this).html();
    }
  }
});


OR

JS Code
$("span.x").qtip({
  content: function(){
    $(this).html();
  }
});


...but it doesn't seem to be working. It only shows an empty qTip box. What am I doing wrong?
Find all posts by this user
Quote this message in a reply
10th December, 11:11
Post: #2
Use hovered element's own HTML for qtip content
discern,

This is actually a commonly asked question and a problem a lot of new jQuery users tend to run into. What you have to get your head around is that $(this) when used in the context of the qTip call is actually just referring to the document or window element, since 'this' outside a function doesn't really have any meaningful value.

What you need to do is give 'this' context by using jQuery's each() method. This loops through each element within the $() DOM array and gives $(this) the value of the current element:

JS Code
$("span.x").each(function(){
   $(this).qtip({
      content: $(this).html()
   });
});

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
10th December, 13:52
Post: #3
Use hovered element's own HTML for qtip content
Thanks very much for the reply, Craig, and for creating such a great tool and standing behind it!
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,232 16th February 09:53
Last Post: johannapelkonen
  [Solved] Getting tooltip to appear on different element with the same class name andrewhoule 5 1,450 25th August 18:17
Last Post: Craig
  [Solved] Take tooltip content from the element attributes AndyG 17 16,083 31st January 07:14
Last Post: eggpoker
  Load an HTML Page Within qTip Tooltip BruceBruce 3 3,327 19th January 12:17
Last Post: Craig
  Style by element class, content by element id teeks 14 5,657 15th November 21:35
Last Post: garbledygook
  [Solved] Using Complex HTML as Tooltip Content sylvia 1 2,419 3rd November 02:07
Last Post: Craig
  qtip-content background in CSS interpotential 4 2,689 25th August 18:48
Last Post: interpotential
  programatically show tip in different element jorfermo 8 2,432 31st March 12:20
Last Post: jorfermo
  How to remove created HTML? kenan 10 2,471 24th December 12:58
Last Post: kenan
  Close a qTip from inside the tip content? ChimneyMedia 3 4,658 6th August 12:36
Last Post: Craig



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