rajasekhar
rajasekhar

Reputation: 17

change the background color

hi this code expalins to the dynamcically add and deletind the rows, if i select the row ,it sholud be change this background color can please help me thanks

Dynamic Creation

$(document).ready(function() {

            $("<table class='table1' border='1'></table>").appendTo(".div1");

            $(".add").click(function() {
                addRows();
            });
            $(".delete").click(function() {
                deleteRows();
            });
            function addRows() {
                $tab = $(".table1");
                $("<tr class='raja'><td>rajasekhar</td><td>hostanalytics</td></tr>").appendTo($tab);
                $(".raja").click(function() {
                $tab.removeClass("selected");
                $(this).addClass("selected");
                });
            }
            function deleteRows() {
                $(".selected").remove();
            }
         });
        </script>

</head>
<body>
    <div class="div1">
        </div>
    <input type="button" class="add" value="InsertRow" />
    <input type="button" class="delete" value="DeleteRow" />
</body>

Upvotes: 0

Views: 165

Answers (1)

kobe
kobe

Reputation: 15835

Raja sekhar ,

As thumb or rule always use live instead of bind when you are dynamically adding and deleting html

$('.test').live('click', function() {
  // Live handler called.
});

read more here

http://api.jquery.com/live/

Upvotes: 2

Related Questions