-5

HTML

<div class="fieldset_div">

<textarea name="subContext_1" class="textcountx" id="textarea__1_1">
  </textarea>
</div>
  • I need to count the number of classes inside a class.
  • I need to find the number of textareas inside the 'fieldset_div'.

Please help.

DreamTeK
  • 32,537
  • 27
  • 112
  • 171
usr111
  • 49
  • 9

3 Answers3

3

Use selector for textarea with .length property:

$('.fieldset_div textarea').length
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
2

To get the amount of classes in a element, try this:

var className = document.getElementById('sidebar').className;
var count = className.trim().split(' ').length + 1;

To get the amount of children a certain element has, you can try this:

document.getElementsByClassName('fieldset_div')[0].childElementCount

However, this doesn't consider wether or not the children are text area's.

Cerbrus
  • 70,800
  • 18
  • 132
  • 147
0

Use:

$('.fieldset_div').find('textarea').length

Demo : http://jsbin.com/favujasivoju/1/

Roy M J
  • 6,926
  • 7
  • 51
  • 78