Mobi Mobi - 7 months ago 11
Javascript Question

How to select second div using jQuery in a webpage?

If a webpage has 2 div tags like

<div>hello</div>
<div>hello</div>


How could I select second div, is it possible using jQuery?

Answer

The following will get the second div using the eq method:

$("div:eq(1)");

EXAMPLE

Please note that @Cerbrus's answer is also correct, you can do this without jQuery.