Affecting a class of a particular row onsubmit

i_user

my page have nested records and each of the nested record has a total number of clicks per each record in a div called "count". I want to add 1 to the total number of each div onclick of the button with a class of view. Currently what i'm achieving is onclick on the button view, 1 is added to the all the nested count divs, but i want it to affect the particular row on which i click the view button

$(document).ready(function(){



$('.view').click(function() {
 counter=parseInt($('.count').html());
            counter++;
            $('.count').html(counter);



        });
    });

html

 <table width="200" border="1">
  <tr>
    <td><div>4</div></td>
  </tr>
  <tr>
    <td><button class="view">CLICK ME</button></td>
  </tr>
  <tr>
    <td><div>12</div></td>
  </tr>
  <tr>
    <td><button class="view">CLICK ME</button></td>
  </tr>
</table>
Drakes

Without IDs, you can use parent() and prev() to access the previous row in the table, then drill down to your div with find().

If there are more than one <div> in your row, then either

  1. Use find("div").eq(x) where x is the div index you want starting from 0 (ref).

  2. Give the div a class name like <div class="count_holder"> and you can then do find("div.count_holder").

Try this:

$(document).ready(function() {

  $('.view').on("click", function() {
    $target = $(this).parent().parent().prev().find("div").eq(1);
    counter = parseInt($target.html());
    counter++;
    $target.html(counter);
  });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table width="200" border="1">
  <tr>
    <td>
      <div>Count:</div>
      <div>4</div>
    </td>
  </tr>
  <tr>
    <td>
      <button class="view">CLICK ME</button>
    </td>
  </tr>
  <tr>
    <td>
      <div>Count:</div>
      <div>12</div>
    </td>
  </tr>
  <tr>
    <td>
      <button class="view">CLICK ME</button>
    </td>
  </tr>
</table>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

while increasing height particular row of data grid view affecting last row also

From Dev

Selecting a table row with a particular class using first-child

From Dev

Add a class to a select options row if particular select option is selected

From Dev

Adding 1 to row value onsubmit

From Dev

Retrieve particular row data

From Dev

displaying the value of a particular row

From Dev

Use glLineWidth for a particular line without affecting other lines

From Dev

find the list of mapping and workflow affecting the particular table in informatica

From Dev

I have to update a particular field without affecting the other field

From Dev

For every row how to add a class name on the <th> based on the value on a particular column using Datatables

From Dev

Making form's onsubmit to work only for particular submits

From Dev

Making form's onsubmit to work only for particular submits

From Dev

CSS only affecting first image in row

From Dev

Swift Protocol of a particular class

From Dev

Get a particular instance of a class

From Dev

Haskell instance declaration affecting interpretation of class

From Dev

jquery affecting all the html elements with same class

From Dev

Disable particular row value in UIPickerView

From Dev

finding the next row with a particular value

From Dev

fetch column value of particular row

From Dev

How to enable textbox in a particular row?

From Dev

Send a particular row of a table to a function

From Dev

sql result show in particular row

From Dev

Webix Pager scroll to particular row

From Dev

Replace a string at particular row and column

From Dev

Repeating particular row of pandas dataframe

From Dev

Loop through particular row in a DataTable

From Dev

Find value in different row and get it to particular row

From Dev

Find value in different row and get it to particular row

Related Related

  1. 1

    while increasing height particular row of data grid view affecting last row also

  2. 2

    Selecting a table row with a particular class using first-child

  3. 3

    Add a class to a select options row if particular select option is selected

  4. 4

    Adding 1 to row value onsubmit

  5. 5

    Retrieve particular row data

  6. 6

    displaying the value of a particular row

  7. 7

    Use glLineWidth for a particular line without affecting other lines

  8. 8

    find the list of mapping and workflow affecting the particular table in informatica

  9. 9

    I have to update a particular field without affecting the other field

  10. 10

    For every row how to add a class name on the <th> based on the value on a particular column using Datatables

  11. 11

    Making form's onsubmit to work only for particular submits

  12. 12

    Making form's onsubmit to work only for particular submits

  13. 13

    CSS only affecting first image in row

  14. 14

    Swift Protocol of a particular class

  15. 15

    Get a particular instance of a class

  16. 16

    Haskell instance declaration affecting interpretation of class

  17. 17

    jquery affecting all the html elements with same class

  18. 18

    Disable particular row value in UIPickerView

  19. 19

    finding the next row with a particular value

  20. 20

    fetch column value of particular row

  21. 21

    How to enable textbox in a particular row?

  22. 22

    Send a particular row of a table to a function

  23. 23

    sql result show in particular row

  24. 24

    Webix Pager scroll to particular row

  25. 25

    Replace a string at particular row and column

  26. 26

    Repeating particular row of pandas dataframe

  27. 27

    Loop through particular row in a DataTable

  28. 28

    Find value in different row and get it to particular row

  29. 29

    Find value in different row and get it to particular row

HotTag

Archive