When I call to a function, it anchors at the top

Using this <a>, i call the function below.

<a href="#" class="Estilo2" onClick="agregar_row('<?=$tabla[nombre];?>');">

… agregar_row.


function agregar_row(tabla){
    for (i=0; i<10; i++){
        row="row/agregar/" + tabla + "/" + i;
        reset_status = "status/agregar/" + tabla + "/" + i;
        if (document.getElementById(row).style.display=='none'){
            document.getElementById(row).style.display='';
            document.getElementById(reset_status).value='S';
            i=11;
        }
        
    }
}

This function is working fine, but each time I call it it makes the browser to point at the top of the page, just if it were calling an anchor to the top. How can I use the function but evade that “repositioning” of the browser?

In IE, FF, Crome, they are the same.

To expand on whisher’s (correct) response a bit, returning false in the onclick statement will stop the browsers from performing their default action for when an anchor element is clicked. This will stop the URL in the address bar from changing to www.whatever.com/#, and should stop the browser from moving to the top of the page.

Hi,
you should do a thing like


onClick="agregar_row('<?=$tabla[nombre];?>'); return false;"


Bye.