JavaScript How to get element by id from the same parent element same line css,element same id html,element same

<button type="button" onclick="method( document.getElementById("panelTxt").value )"></button>

Don't include the # in your ID of getElementById as suggested in comments.

Answer:1

Here is an unobtrusive way to get the value of the textarea after ANY button in the panel

document.querySelectorAll(".panel>button").forEach(function(but) {
  but.addEventListener("click",function(e) {
    e.preventDefault();
    console.log(this.nextElementSibling.value);
  });
});
<div id="panel1" class="panel">
   <button id="c1">Click</button>
   <textarea id="c2">value 1</textarea>
</div>
<div id="panel2" class="panel">
   <button id="c3">Click</button>
   <textarea id="c4">value 2</textarea>
</div>
Answer:2

First I suggest avoiding the use of inline-event onclick and attach the event in your JS code using addEventListener(), then it will be better to use nextElementSibling property and get the content of the next field using value:

document.getElementById('panelBtn').addEventListener('click', function() {
  console.log(this.nextElementSibling.value);
})
<div id="Panel">
  <button id="panelBtn" class="button">Click Me</button>
  <textarea id="panelTxt" class="textarea">Insert text here</textarea>
</div>
Answer:3

I'm using Template.uploadFile.events({ 'change .set-file': function ( event, template ) { var file = event.currentTarget.files[0]; [...] } }); when uploading a file. I want to read ...

I'm using Template.uploadFile.events({ 'change .set-file': function ( event, template ) { var file = event.currentTarget.files[0]; [...] } }); when uploading a file. I want to read ...

  1. shiny update reactive variable
  2. r shiny update reactive variable
  3. shiny update reactive values

I have a screen in my app that has a "in between" content. This content is too long for the Iphone 5-8, but just one screen for the Iphone 8S-XS Max. To fix it, I've put on a simple ScrollView, ...

I have a screen in my app that has a "in between" content. This content is too long for the Iphone 5-8, but just one screen for the Iphone 8S-XS Max. To fix it, I've put on a simple ScrollView, ...

  1. react native scrollview fill height
  2. react native scrollview full screen

I am working on an application that uses angular js UI grid. But as and when I keep using my application, it keeps adding up to the memory without releasing the dom objects. I have created a sample ...

I am working on an application that uses angular js UI grid. But as and when I keep using my application, it keeps adding up to the memory without releasing the dom objects. I have created a sample ...

  1. ag-grid angular memory leak
  2. angularjs ui grid memory leak

I need to transfer state of a component to its parent component, but I don't need to transfer all fields. What I currently do: submitHandler = (e) => { e.preventDefault(); const ...

I need to transfer state of a component to its parent component, but I don't need to transfer all fields. What I currently do: submitHandler = (e) => { e.preventDefault(); const ...

  1. copy state object react
  2. copy object state
  3. vuex copy state object
  4. reactjs copy state object
  5. redux copy state object
  6. python copy object state