简体   繁体   中英

Change the name of HREF link

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.

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

Try this out..

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

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

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

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

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

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; .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM