Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] Passing variables into content: api: data
20th August, 16:01
Post: #1
[Solved] Passing variables into content: api: data
Using v2. Assuming this question is due to only having a surface level knowledge of Javascript.

I have qtip working, and loading content via api, but I'd like to pass along a variable from out of each particular instance, in this case the value of the rel attribute would work just fine.

But when I use
JS Code
$(this).attr("rel")
, nothing comes through. I suppose the $(this) is not in the right context to work?

JS Code
$(".pl-name a").qtip({
		style: {
		      classes: 'ui-tooltip-player-intro-style'
		},		
		content: {
			text: 'Loading...',
			ajax:{
				url:"ajax_player_intros.php",
				data: {
					player: $(this).attr("rel")
					},
				type : "POST",
 
			success: function(api, data){                  
			        console.log(data);
					console.log(this.elements.target.attr('rel'))
				}	
			},		
		},
		position: { 
		   my: 'top left', 
		   at: 'top right'
		}
	});


Thanks in advance for tips/help.
Find all posts by this user
Quote this message in a reply
20th August, 18:31
Post: #2
RE: Passing variables into content: api: data
Try wrapping your call in an each() method first, this sets "this" to reffer to the current element within the loop:

JS Code
$(".pl-name a").each(function(){
	var attr = $(this).attr('rel');
 
	$(this).qtip({
		style: {
			classes: 'ui-tooltip-player-intro-style'
		},
		content: {
			text: 'Loading...',
			ajax:{
				url:"ajax_player_intros.php",
				data: {
					player: attr
				},
				type : "POST",
				success: function(api, data){
					console.log(data);
					console.log(attr);
				}
			},
		},
		position: {
			my: 'top left',
			at: 'top right'
		}
	});
});

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
20th August, 18:53
Post: #3
RE: [Solved] Passing variables into content: api: data
Woohoo! It worked. Thanks so much.

Note: Line two was missing parenthesis after "this", should be:

JS Code
var attr = $(this).attr('rel');
Find all posts by this user
Quote this message in a reply
16th September, 07:58
Post: #4
RE: [Solved] Passing variables into content: api: data
This should be a tutorial, This is very useful for creating drop menu's or pop up content (more than what could be put in a title attr)[/code].
JS Code
<style type="text/css">
.TipContent{
	display: none;
}
</style>
<script type="text/javascript">
$(function() {
	$(".toolTip").each(function(){
		var attr = $(this).attr('id');
		$(this).qtip({
			content: $("#show" + attr),
			position: {
				my: 'bottom center', 
				at: 'top center',
				adjust: {
					screen: true,
					resize: true
 
				}
			},
			style: {
				tip:true,
 
				classes: 'ui-tooltip-blue ui-tooltip-shadow'
			},
			hide: {
				fixed: true
			}
		});
	});
});
 
</script>

JS Code
<div class="toolTip" id="Tip1">
<strong>What Ever</strong>
</div>
<div class="TipContent" id="showTip1">Pimping</div>

It took me forever to figure out the each, and only because I found it in the forums.
Find all posts by this user
Quote this message in a reply
16th September, 14:12
Post: #5
RE: [Solved] Passing variables into content: api: data
Also just a quick FYI, as of the latest commits you can also use a custom function for your content so you don't need to use an .each() loop!

JS Code
$(function() {
   $(".toolTip").qtip({
         content: function() { return $("#show" + $(this).attr('id')); },
         position: {
            my: 'bottom center', 
            at: 'top center',
            adjust: {
               screen: true,
               resize: true
 
            }
         },
         style: {
            tip:true,
 
            classes: 'ui-tooltip-blue ui-tooltip-shadow'
         },
         hide: {
            fixed: true
         }
   });
});


Enjoy!

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
9th October, 15:53
Post: #6
RE: [Solved] Passing variables into content: api: data
Maybee you can help me, but in the show/hide event how do i access the id $(this).attr('id')
JS Code
$(function() {
   $(".toolTip").qtip({
         content: function() { return $("#show" + $(this).attr('id')); },
         position: {
            my: 'bottom center', 
            at: 'top center',
            adjust: {
               screen: true,
               resize: true
 
            }
         },
         style: {
            tip:true,
 
            classes: 'ui-tooltip-blue ui-tooltip-shadow'
         },
         hide: {
            fixed: true
         },
		 events: {
			  show: function(event, api) {
				 alert ($(this).attr('id'));
			  },
			  hide: function(event) {
				 alert ($(this).attr('id'));
			  }
		 }
   });
});
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  qTip2 shows and hides slowly with large data set zack.macomber@gmail.com 3 85 13th May 12:55
Last Post: Craig
  [Solved] api.elements.tooltip ... can i set tooltip content with this? brid 2 60 11th May 19:17
Last Post: brid
  [Solved] passing rel id to php gcombe74 1 122 20th April 17:53
Last Post: gcombe74
  [Solved] AJAX and Dynamic Input Data jWOS 2 216 8th April 19:35
Last Post: jWOS
  [Solved] api.set of style.height? cssagogo 2 325 21st February 22:38
Last Post: cssagogo
  [Solved] Data selection in AJAX. Diixi 4 936 3rd January 21:04
Last Post: Craig
  [Solved] How can I pass some data to modal klauzito 3 726 27th November 14:59
Last Post: Craig
  [Solved] Passing a variable to a .php Teksonic 5 722 21st November 19:45
Last Post: Teksonic
  [Solved] [Solved] passing $(this).attr('id') via ajax as data jerrye 3 1,800 25th August 17:53
Last Post: snaky
  Accesing the API without having to load qtip on document.ready alfonso_a_g 1 764 23rd August 15:35
Last Post: Craig



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