Question: How can we get values of form elements inside fieldset?

```
<fieldset id='myFieldset'>
  <label for='Resp'>Responsibilities</label><input id='input' type='text' size='55'>
  <button type='button' class='btn-sm' style='width:50px;margin:2px' id='addItem'>Add</button>
  <button type='button' class='btn-sm' style='width:50px;margin:2px' id='clear'>Clear</button>
  <button type='button' class='btn-sm' style='width:50px;margin:2px' id='edit'>Edit</button>
  <ul id='output' style='display:none'></ul>
  <br class='clear' /> 
  <textarea disabled name='Resp' id='Resp' cols='75' rows='5' required></textarea>
</fieldset>

```

I have some more fields similar to this in a page. So I need to get values from input form and also from specific fieldset. How can I do it in jQuery?

Answer: 
Here you go with the solution <https://jsfiddle.net/f3xwzap9/>

```js
var data = {};

$('#addItem').click(function(){
  $('fieldset#myFieldset > input, textarea').each(function(){
    data[$(this).attr('id')] = $(this).val();
  });

 console.log(data);
});
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<fieldset id='myFieldset'>
  <label for='Resp'>Responsibilities</label><input id='input' type='text' size='55'>
  <button type='button' class='btn-sm' style='width:50px;margin:2px' id='addItem'>Add</button>
  <button type='button' class='btn-sm' style='width:50px;margin:2px' id='clear'>Clear</button>
  <button type='button' class='btn-sm' style='width:50px;margin:2px' id='edit'>Edit</button>
  <ul id='output' style='display:none'></ul>
  <br class='clear' /> 
  <textarea name='Resp' id='Resp' cols='75' rows='5' required></textarea>
</fieldset>
```

I have attached an event in **Add** button.
I'm **looping** through all the **input** & **textarea** inside the **fieldset** & collecting the data.

Data is in JSON format **id as key** and **value is value**.

Since I'm looping through all the **input** & **textarea**, it will help you to collect all the **child** (**input** & **textarea**) data, rather than collecting the data specifically.
$('#myFieldset').find('input').val()