$("#AddDataStavka, #AddDataRazmer").on("keyup", function (event) { if (event.keyCode == 13) { e.preventDefault(); $("tr.trNewLine").children().first().children().first().get(0).click(); } }); /*This is code inside a document.ready, what I'm trying to do is call this every time a button is pressed and if its the enter key it should click the button. What am I doing wrong? Here's what I'm trying to target:*/ <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <tr runat="server" id="trNewLine" class="trNewLine" visible="false"> <td runat="server" id="operationCol3"> <asp:LinkButton ID="btnAddDataAdd" runat="server" class="btn btn-pireus" OnClick="btnAddAddData_Click" ToolTip="Добави застраховка"><span>Добавяне</span></asp:LinkButton></td> <td> <asp:DropDownList runat="server" ID="AddDataType" class="DropDownListHint" data-taggle="dropdown" data-style="DropDownListHint-datastyle" OnSelectedIndexChanged="AddDataType_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList> </td> <td> <input type="text" class="form-control form-control-pireus" id="AddDataStavka" clientidmode="static" onchange="glowInsuranceCheck()" runat="server" maxlength="15" text=''> </td> <td> <select class="DropDownListHint" id="AddDataRisk" runat="server" data-placement="top" data-taggle="dropdown" data-style="DropDownListHint-datastyle"></select> </td> <td> <input type="text" class="form-control form-control-pireus bst-suma" id="AddDataRazmer" clientidmode="static" onchange="glowInsuranceCheck()" runat="server" maxlength="19"> </td> <td> <select class="DropDownListHint" id="AddDataInsurer" runat="server" data-placement="top" data-taggle="dropdown" data-style="DropDownListHint-datastyle"></select> </td> <td> <select class="DropDownListHint" id="AddDataInsured" runat="server" data-placement="top" data-taggle="dropdown" data-style="DropDownListHint-datastyle"></select> </td> </tr>
ewhich is undefined What button are you trying to click?event.preventDefault();instead ofe.preventDefault();because in your code theeis not defined.