1

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?

3 Answers 3

1

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')
Sign up to request clarification or add additional context in comments.

Comments

1

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\">');

2 Comments

missing quote in first statement
@TStamper There's no missing quote ;-)
1

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');
            }
     );
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.