We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Friday, July 17, 2015

Applying Attribute And removing attribute in jQuery



<html>
<head>
    <title></title>
    <script src="Scripts/jquery-2.1.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#btn1,#btn2").click(function () {
                var id = $(this).attr("id");
                if (id == "btn1") {
                    $("#img1").attr({ "src": "images/mk2.jpg", "alt": "This is image", "title": "image", "style": "border:5px red" });
                }
                else if (id == "btn2") {
                    $("#img1").removeAttr("src style");
                }
            });
        });
    </script>
</head>
<body>
    <form id="form2" runat="server">
    <div>
        <input id="btn1" type="button" value="Applying Attribute" />
        &nbsp;
        <input id="btn2" type="button" value="Removing Attribute" />
        <br /><br />
        <img id="img1" src="images/mk8.jpg" width="300" height="300" />  

    </div>
    </form>
</body>
</html>


No comments: