Jump to content

Recommended Posts

ok im working on making a tooltip script using jquery...

 

my tooltips are stored un this type of fashion..

 

<script type="text/javascript">
<!--//--><![CDATA
var tiplib_1 = "Search items and recipes in the database";
var tiplib_2 = "Roster Configuration Panel";
var tiplib_3 = "Add a new guild and synchronize<br \/>the memberlist with Blizzard\'s Armory";
var tiplib_4 = "Image screenshot database";
//--><!]]>
</script>

 

this is located at the bottom of my page .. my question is how would i call this info so i can place it in a div container

 

<div data-tip="tiplib_1" >This is link #4</div>

 

$(document).ready(function(){
 simple_tooltip("[data-tip]","tooltip");
});

starts mt script

function simple_tooltip(target_items, style){
$(target_items).each(function(i){

 var Tip_name = $(this).attr("data-tip");
 //$("body").append("<div id='"+$(this).attr("data-tip")+"'>"+$($(this).attr("data-tip"))+"</div>");
 var myar = Tip_name.split('_');
 alert("id "+i+"- "+$(this).attr("data-tip")+"-"+myar[1]+"");
 $("<div id='"+Tip_name+"'>"+$(this).attr("data-tip")+"</div>").appendTo("body")
 $("#"+Tip_name).html(Tip_name);
 var my_tooltip = $("#"+Tip_name);

 

Tip_name has the name of the var i wana call but for the life of me i cannoe make use get the value of the var and put it in the div any help?

Link to comment
https://forums.phpfreaks.com/topic/268757-variables-in-jquery/
Share on other sites

If you're going to store the tips separately like that, then use an array, not just sequentially numbered variables. However, why don't you just store the tooltip text directly in the data attribute (or the title attribute) and not even bother with the array:

 

//<div data-tip="Search items and recipes in the database">blah blah</div>
function simple_tooltip(target_items, style){
  $(target_items).each(function(i){
     var tipText = $(this).attr('data-tip');
     var tipDiv = $("<div>");
     tipDiv.appendTo(document.body).html(tipText);
  }
}

 

Completely untested, but something like that.

Link to comment
https://forums.phpfreaks.com/topic/268757-variables-in-jquery/#findComment-1380690
Share on other sites

the reason they are stored as such is because they contain html

 

That's not an issue. You just have to escape the HTML properly. Eg:

<div data-tip="<h1>Some title</h1><p>This is the tooltip "content"</p>">Something</div>

 

Like I said though, if you want to keep them separate, use an array:

<script type="text/javascript">
var tooltipStrings = [
  "Search items and recipes in the database",
  "Roster Configuration Panel",
  "Add a new guild and synchronize<br \/>the memberlist with Blizzard\'s Armory",
  "Image screenshot database"
];
</script>

 

Then set the index # as the data attribute, eg <div data-tip="2">blah</div>

 

And finally to get the string you'd do:

var tipIndex=$(this).attr('data-tip');
var tipText = tooltipStrings[tipIndex];

 

Using eval is about the worst possible thing you could do.

Edited by kicken
Link to comment
https://forums.phpfreaks.com/topic/268757-variables-in-jquery/#findComment-1380726
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.