masteringprojects masteringprojects - 2 months ago 7
HTML Question

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 !

Answer

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.