Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

a href link that will act like a button

Is there any clean method to make a regular link :

<a href="[8]">Click here to read more...</a>

to act EXACTLY like a button

<button id="[8]">Click here to read more...</button>

Thanks !

like image 739
masteringprojects Avatar asked Jan 01 '14 23:01

masteringprojects


1 Answers

Do you mean something like this?

<a id="[8]" class="readmore" href="#">
    Click here to read more...
</a>

Adapting your javascript to the new "a":

$("a.readmore").click(function() { 
    var id=this.id.split('['); 
    var d_id=id[1].split(']'); 
    var ii=d_id[0] $('html, body').animate({ 
       scrollTop: $('[id='+ii+']').offset().top 
    }, 2000); 

    return false;
});

Just a tip, your string processing looks terrible, suggestion:

$("a.readmore").click(function() { 
    var id=this.id.match('[0-9]+');

    $('html, body').animate({ 
       scrollTop: $('[id='+ id +']').offset().top 
    }, 2000); 

    return false;
});

Ensure this code is being intercept by the page dom parser in the right time, put it inside a

$(document).ready(function(){ ... });

Regards.

like image 65
João Pinho Avatar answered Sep 22 '22 00:09

João Pinho