用ajax改变值

I have button, and when I click on it it run ajax that should change "startRow" values', but it doesn't.

Why is that? Here is the code -

<div id="commentsBox">
<?PHP 
    $startRow = 0;
    print_comments ($_GET['page'], $_GET['ownerID'], $startRow)
?>
</div>
<button class="btn btn-primary" id="moreComments" startRow='0' pageName="userPage" refID="<?PHP echo $_GET['ownerID'] ?>">MORE</button>

AJAX:

$(function () {
    $("#moreComments").click(function () {
        var element = $(this);
        var startRow = element.attr("startRow");
        var pageName = element.attr("pageName");
        var refID = element.attr("refID");
        var info = 'startRow=' + startRow + '&pageName=' + pageName + '&refID=' + refID;
        $.ajax({
            type: "POST",
            url: "ajax/moreComments.php",
            data: info,
            success: function (data) {
                $('#commentsBox').append(data);
                startRow = startRow + 20;
                $("#moreComments startRow").val(startRow);
                //element.attr( 'startRow' , startRow);
            }
        });
        return false;
    });
});

You ajax call is ok. The problem is that you are using the jQuery selector wrong.

Instead of this:

$("#moreComments startRow").val(startRow);

You should do this

$("#moreComments").attr("startrow",startRow);

In the first one, you are trying to access to a child of moreComments and startRow is just an attribute of moreComments.

Hope it helps!