ako ako - 5 months ago 12
jQuery Question

jquery not work in asp.net

i have an asp.net website i want when a label is clicked then an alert for example be fired using jquery but it does not work :
here is what i tried :

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript">
$('#scheduled').click(function () {
alert("alert something");//not work
});
$('.ako').click(function (e) {
alert("alert something");//not work
});
$("#<% =scheduled.ClientID%>").click(function (e) {
alert("alert alert alert");//not work
});
</script>



and here is the Label tag :

<asp:Panel runat="server" CssClass="row">
<asp:Label runat="server" CssClass="btn btn-primary btn-lg " class="ako" Style="margin: 10px" ID="scheduled" Text="scheduled" />
</asp:Panel>


i user master page and this code is in Default.aspx page .

none of jquery ( javascript ) alerts work .
thanks .

Answer

Wrap the code by document ready handler to bind event handler after elements are loaded or move the code at the end of page.

$(document).ready(function(){
    $('#scheduled').click(function () {
        alert("alert something");//not work
    });
    $('.ako').click(function (e) {
        alert("alert something");//not work
    });
    $("#<% =scheduled.ClientID%>").click(function (e) {
        alert("alert alert alert");//not work
    });
});
Comments