tags:

views:

235

answers:

3

I am trying the following:

var showTooltip = function(event) {
if(event.target == "<a href=\"view_repair.php\">") {
$tooltip
  .text('View full repair details')
  .fadeIn('slow');
positionTooltip(event);

console.log(event.target) in Firebug gives

<a href="view_repair.php">

But the code inside the if statement isn't being run. Is this because the if statement is comparing against the actual string it's being given - including the escapes?

When I change the if statement to:

if(event.target == event.target)

I get the desired result.

What I'd really like to be able to do is use the link name/title to do the comparison, i.e. (pseudo code):

if(event.target.text() == "View")

Is this possible in any way?

A: 

You're trying to compare a DOM element object with a string representation of what it's tag might look like, which aren't equal. How about something like:

if(event.target.attr('href') == 'view_repair.php')
No Surprises
+1  A: 

try

alert('event target is:' + event.target);

This should tell you the value.

You can test your value for comparison with

alert('<a href=\"view_repair.php\">');
Chris Ballance
missing quote in first statement
TStamper
@TStamper There's no missing quote ;-)
Chris Ballance
lol...smooth you did it before the edit flag caught it
TStamper
+1  A: 

Why not give the link a title attribute and extract the tooltip text from it, then remove it. Then you don't have to hardcode any values in your function.

 <a href="view_repair.php" title="View full repair details" class="tool">View</a>


 $('.tool').each( function() {
     var $this = $(this);
     var tip = $this.attr('title');
     $this.removeAttr('title');
     $this.hover(
            function(e) {
                $tooltip.text(tip).fadeIn('slow');
                positionTooltip(e);
            },
            function(e) {
                $tooltip.fadeOut('slow');
            }
     );
});
tvanfosson