-1

How can i select in the most easiest way the second occurrence of element type div in a given element(parent).

For example:

div
   span
   div
   pre
   div ==i want this ==
/div
Muhammad Umer
  • 17,263
  • 19
  • 97
  • 168

2 Answers2

1

Assuming the parent div has a class of parent for example:

$("div.parent").find("div").eq(1);
kei
  • 20,157
  • 2
  • 35
  • 62
  • 1
    Depends how complex your DOM tree is. See related question [**here**](http://stackoverflow.com/questions/648004/what-is-fastest-children-or-find-in-jquery). This is assuming you don't have nested divs, and so `.find()` would actually be faster. – kei Oct 31 '14 at 17:27
0

Try using div:eq()

$("#parent_div div:eq(1)")

Example

<div id="parent_div">
    <span></span>
    <div>1</div>
    <span></span>
    <div>2</div>
</div>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script>
    var test = $("#parent_div div:eq(1)").text(); //eq(1) is 2nd div
    alert(test);
</script>
MH2K9
  • 11,951
  • 7
  • 32
  • 49