Saturday, 29 October 2016

jQuery - Check if control exists

Watch this example on YouTube:


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
   
    <script  type="text/javascript" src="Scripts/jquery-1.10.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            jQuery.fn.exists = function () { return this.length > 0; }
            if ($('#Button1').exists()) {

                alert('control exists');
            }
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>

No comments:

Post a Comment