views:

141

answers:

6

Hi there, i have the following link

<a href="example.com" id="example1"> Go to example....</a>

Is it possible that when a body moves the cursor over "Go to example..." it changes to "Go to example One" , i am using php and jquery. Any help will be appreciated.

+2  A: 

Shouldn't be too difficult using jQuery:

$('#example1')
    .mouseover(function(e) { $(this).text('Go to example One') })
    .mouseout(function(e) { $(this).text('Go to example...') });

Remove the second bind if you don't need it to go back to "..." when the user moves the mouse away.

Edit: Forgot about the mouseover helper method

Richard Szalay
+1  A: 

Try this out..

$('#example1').mouseover(function() {
    $(this).text('Go to example One');
});

Ya missed the # I was trying to get in quick ;)

anthonyv
Since it is an id selector you have to use # in front of example1
rahul
+2  A: 
$(function(){
    $("#example1").mouseover(function(){
        $(this).text('Go to example One');
    });
});

or you can use the hover function like

$(function(){
    $("#example1").hover(
      function () {
        $(this).text('Go to example one');
      }, 
      function () {
        $(this).text('Go to example....');
      }
    );
});
rahul
+1: I prefer hover() to my method
Richard Szalay
A: 

here is the PHP code

<span
class="trackTitle"> <a href="<?php print  "play/".$link;?>" title="Listen or Download <?php echo $hoverActual ?>"  onmouseover="javascript:changeTo('<?php echo $hoverActual; ?>');"><?php echo $fileName; ?></a></span>

where the Function changeTo is used, i want to change $fileName; .

Ahsan
Using event attributes like `onmouseover` is considered bad practice.
Richard Szalay
A: 

The .hover() helper is useful here, to prevent annoying event bubbling:

var elem = $('#examle1'), orig = elem.text();
elem.hover(
    function() { $(this).text('Go to example One'); },
    function() { $(this).text(orig); }
);
David
A: 

You can even do that with CSS only. You just need two elements in your link that you can address like:

<a href="example.com" id="example1"> Go to example <em>…</em> <span>One</span></a>

And the corresponding CSS behavior:

a span,
a:hover em {
    display: none;
}
a:hover span {
    display: inline;
}
Gumbo