JavaScript Add selected class to table row when click on that row class selected table

i have table

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="activity_tab">
    <tr id="list_1">
        <td><span class="new_act">Folder files Created</span>
        </td>
        <td>2013-06-24 02:11 am</td>
    </tr>
    <tr id="list_2">
        <td><span class="new_act">Folder ss Created</span>
        </td>`enter code here`
        <td>2013-06-24 02:11 am</td>
    </tr>

and its dynamic table data comes on run time when i click on a row i want to add selected class to that row. after that i have hyper link at top of page

 <li><a target='_blank' href="javascript:void(0);" class="delete">Delete</a></li>

this is my hyperlink now when click on hyperlink the selected row will bhe deleted how can i get the selected row and i have all idea about its deletion but could'nt find any solution...

Answer:1

I would add a class on the selected row. I'm assuming you can only have one selected row at a time, so you'll need to remove any selections when a new row is clicked.

Since your table is dynamic, you'll need to use a delegated event listener to add the selected class. See the documentation of jQuery's on() method for more details on delegated events.

$(document).on('click', 'tr', function(e) {
    $('tr.selected').removeClass('selected'); //clear other selections
    $(this).addClass('selected'); //mark this row as selected
});

$('a.delete').on('click', function(e){
   e.preventDefault(); //stop native link behavior
   $('tr.selected').remove(); //remove selected row
});

Note that the listener that adds the selected class to a row will affect any tr element in the document. If you have other tables on your page, you will need to make the second selector (after the 'click') more specific.

Answer:2

You can try this

$(function(){
    $(".activity_tab tr").click(function(){
        $(this).addClass("red");
    });

    $('.delete').on('click',function(){
       $('tr.red').remove();
    });
});

Demo: http://jsfiddle.net/YNNVr/

Answer:3

i have a base class function Base(){ this.children = new Array(); } Base.prototype.Add = function(child){ this.children.push(child) } function Sub1(){...} Sub1.prototype = new Base(); ...

i have a base class function Base(){ this.children = new Array(); } Base.prototype.Add = function(child){ this.children.push(child) } function Sub1(){...} Sub1.prototype = new Base(); ...

  1. how does this javascript work
  2. does javascript have classes
  3. does javascript need semicolons
  4. does javascript pass by reference
  5. does javascript require semicolons
  6. does javascript support automatic type conversion
  7. does javascript allow exception handling
  8. does javascript have garbage collection
  9. does javascript support inheritance
  10. does javascript have interfaces
  11. does javascript compile
  12. does javascript have pointers
  13. does javascript have dictionaries
  14. does javascript have inheritance
  15. does javascript alert stop execution
  16. does javascript support multithreading
  17. does javascript cost money
  18. does javascript work on iphone
  19. does javascript map preserve order
  20. does javascript support multiple inheritance

Heres my problem. Might be a bit trivial. I am using node.js to write a form which has radio buttons, drop down boxes. I have been able to save data and also retrieve it successfully but I am not able ...

Heres my problem. Might be a bit trivial. I am using node.js to write a form which has radio buttons, drop down boxes. I have been able to save data and also retrieve it successfully but I am not able ...

I used the Push Plugin in the app.ready() like this https://github.com/phonegap-build/PushPlugin window.onNotification = function(e) { switch( e.event ) { case 'registered': ...

I used the Push Plugin in the app.ready() like this https://github.com/phonegap-build/PushPlugin window.onNotification = function(e) { switch( e.event ) { case 'registered': ...

  1. data binding between components
  2. data binding between components angular 6
  3. data binding between components angular
  4. data binding between components angular 4
  5. data binding between components lightning
  6. data binding between parent and child component
  7. data binding between components angularjs
  8. data binding between two components
  9. data binding between components vue
  10. data binding between components angular 7
  11. data binding between components angular 8
  12. angular data binding between two components
  13. angularjs data binding between controllers
  14. c# data binding between classes
  15. wpf data binding between windows
  16. angular2 data binding between components
  17. two way data binding between components
  18. two way data binding between components angular
  19. two way data binding between controller and directive
  20. two way data binding between components angular 4

Using React Native's experimental animation library, what toValue is required to animate the scaling of an element to 0? This does nothing: Animation.startAnimation({ node: button, duration: 500,...

Using React Native's experimental animation library, what toValue is required to animate the scaling of an element to 0? This does nothing: Animation.startAnimation({ node: button, duration: 500,...

  1. what syntax does tableau use
  2. what syntax does yoda use
  3. what does syntax mean
  4. what does # syntax refers
  5. what does syntax error mean
  6. what does # syntax refers for in sass
  7. what does syntax mean in literature
  8. what does syntax mean in programming
  9. what does syntax
  10. what does syntax mean in coding
  11. what does syntax error mean in python
  12. what does syntax mean in python
  13. what does syntax study
  14. what does syntax include
  15. what does syntax mean in english
  16. what does syntax error mean on a calculator
  17. what does # syntax refers in sass interpolation
  18. what does syntax mean in writing
  19. what does syntax mean in excel
  20. what does syntax error mean in minecraft