javascript - Get number of elements inside of an element in xml with jQuery -


i have xml file:

<row>     <question name="faq"></question>     <answer name="faq"></answer>     <question_down name="faq"></question_down>     <answer_down name="faq"></answer_down>     <question_down name="faq"></question_down>     <answer_down name="faq"></answer_down>     <question_down name="faq"></question_down>     <answer_down name="faq"></answer_down> </row> 

i want know how many <question_down> elements have inside <row>, how can using jquery or pure javascript?

you can use jquery's .find() method here find specific elements within element. here want find <question_down> inside <row>

question_down_num = $("row")    //any <row> element    .find("question_down")        //find  element called <question_down> in <row>    .length;                      //find length of <question_down> array,                                     //i.e. how many <question_down> elements exist in <row>  document.write(question_down_num);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <row>    <question name="faq">  </question>    <answer name="faq"></answer>    <question_down name="faq"></question_down>    <answer_down name="faq"></answer_down>    <question_down name="faq"></question_down>    <answer_down name="faq"></answer_down>    <question_down name="faq"></question_down>    <answer_down name="faq"></answer_down>  </row>


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -