2014-05-23 01:57



Basically I want my tooltip to display company names once company_id is being hovered. However instead of displaying "Company A" for example, it just displays "Company". I realized that it's just printing everything before a space.

Here's the script:

<script type="text/javascript">
  $(document).ready(function() {
  // Tooltip only Text
    // Hover over code
    var title = $(this).attr('title');
    $(this).data('tipText', title).removeAttr('title');
    $('<p class="tooltip"></p>')
}, function() {
    // Hover out code
    $(this).attr('title', $(this).data('tipText'));
 }).mousemove(function(e) {
    var mousex = e.pageX + 20; //Get X coordinates
    var mousey = e.pageY + 10; //Get Y coordinates
    .css({ top: mousey, left: mousex })

and here's my codes

  $companyCtrl = new company_controller();
  $companyInfoArr = $companyCtrl->retrieveAllCompanyInfo();
  foreach($companyInfoArr as $info) {
    $company_id = $info->getCompanyID();
    $company_name = $info->getCompanyName();
    echo "<a href='#' title=".$company_name." class='masterTooltip'>".$company_id."</a> <br>";

There's not problem when i manually enter the text like this

<a href="#" title="This will show up in the tooltip" class="masterTooltip">Your Text</a>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongyunque2511 dongyunque2511 7年前

    In this line:

    echo "<a href='#' title=".$company_name." class='masterTooltip'>".$company_id."</a> <br>";

    You need to add quotes around the title, so the HTML you're generating will be properly formed. Like this:

    echo "<a href=\"#\" title=\"".$company_name."\" class=\"masterTooltip\">".$company_id."</a> <br>";
    点赞 评论 复制链接分享