views:

204

answers:

4

Hi Friends,

I need to find out the number <input> tag within a <Div> tag.. How it's possible.. For example the code will be like this..

<div><li ><a>Jayan</a><input type="checkbox" id="c21" onClick="fcheck(this);" ></li>
<li ><a href="#">Reshaba</a><input type="checkbox" id="c22" onClick="fcheck(this);" >
 <ul>
  <li ><a>crescent</a><input type="checkbox" id="c221" onClick="fcheck(this);" ></li>
  <li ><a>crescent</a><input type="checkbox" id="c222" onClick="fcheck(this);" ></li>
  <li ><a>crescent</a><input type="checkbox" id="c223" onClick="fcheck(this);" ></li>
  <li ><a>crescent</a><input type="checkbox" id="c224" onClick="fcheck(this);" ></li>
 </ul>
</li></div>

Please help

Thanks,
Praveen J

+3  A: 

Take a look at the getElementsByTagName method.

Jon Grant
A: 

Use jQuery:

$("div input").length
svinto
+2  A: 

Very easy if you can use jQuery:

$('#divId input').length;

Otherwise @Jon Grant's answer is what you need

Keith
+9  A: 

Why always the jquery solutions ? There is nothing wrong with using jquery, but including a JS library to count some elements is serious overkill.

Native javascript:

var inputCount = document.getElementById('divId').getElementsByTagName('input').length;
I.devries
+1 for doing it without a framework. I agree, for something as simple as this, a framework is overkill.
Andreas Grech
+1 - put jQuery in your answer if the question is about jQuery - or if there is a serious benefit to be derived from its use.
Sohnee