JavaScript JQuery : Get div defined in same table row

I have an HTML table created dynamically using an MVC application and the output of the table is as shown below:

In the onclick event of the edit button I want to show divText and hide divLabel of the same row using jQuery.

I have tried to get divLabel as shown below:

function EditRecord(elem) {
  var divlabel = $(elem).closest('tr').children('td div#divLabel');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
  <tr>
    <td>
      <div id="divLabel">
        value 1
      </div>
      <div id="divText" style="display: none">
        <input type="text" value="value 1" />
      </div>
    </td>
    <td>
      <input type="button" value="edit" onclick="EditRecord(this);" />
    </td>
  </tr>
  <tr>
    <td>
      <div id="divLabel">
        value 2
      </div>
      <div id="divText" style="display: none">
        <input type="text" value="value 1" />
      </div>
    </td>
    <td>
      <input type="button" value="edit" onclick="EditRecord(this);" />
    </td>
  </tr>
</table>
Answer:1

Try This one It should work for me

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
  function EditRecord(elem) {
    var chg = $(elem).closest('tr').children('td').siblings(':first-child');
    chg.find('div:first-child').hide();
    chg.find('div:nth-child(2)').show();
        }
</script>
</head>
Answer:2

I'm trying to read in several urls as text and store them into an array with jquery's ajax/get. I need to wait for all data to be obtained (and pushed to an array) and then return it in a function. ...

I'm trying to read in several urls as text and store them into an array with jquery's ajax/get. I need to wait for all data to be obtained (and pushed to an array) and then return it in a function. ...

  1. multiple ajax requests jquery
  2. multiple http requests jquery
  3. prevent multiple requests jquery
  4. multiple simultaneous ajax requests jquery
  5. jquery multiple requests
  6. handling multiple ajax requests jquery
  7. prevent multiple ajax requests jquery

Say I have the following HTML code (it's an example): <div id="site_header_container" class="site_bar_container"> <div id="site_header"> <div id="header_logo_container"> ...

Say I have the following HTML code (it's an example): <div id="site_header_container" class="site_bar_container"> <div id="site_header"> <div id="header_logo_container"> ...

  1. position element relative to another
  2. position element relative to parent
  3. position element relative to viewport
  4. position element relative to sibling
  5. position element relative to another css
  6. position element relative to window
  7. position element relative to parent div
  8. position element relative to screen
  9. position element relative to browser window
  10. position element relative to another javascript
  11. position element relative to another jquery
  12. position element relative to grandparent
  13. position element relative to page
  14. position element relative to other element
  15. position element relative to viewport css
  16. css position element relative to sibling
  17. html position element relative to another
  18. css position element relative to window
  19. css position element relative to screen
  20. react position element relative to another

I'm familiar with using jQuery's $.ajax: $.ajax({ url: //twitter endpoint, method:"GET", dataType:"jsonp", success:function() { //stuff } }); How can I specify the JSONP datatype to an ...

I'm familiar with using jQuery's $.ajax: $.ajax({ url: //twitter endpoint, method:"GET", dataType:"jsonp", success:function() { //stuff } }); How can I specify the JSONP datatype to an ...

  1. json specify data type

I have a small JavaScript graphing/histogramming library which allows zooming/panning in either X or Y directions, or both, as declared when the plot is created. A simplified example is in this ...

I have a small JavaScript graphing/histogramming library which allows zooming/panning in either X or Y directions, or both, as declared when the plot is created. A simplified example is in this ...