Jquery: next() and nested elements

Hi,
I have nested elements like below,

<div>
		<p>Hello Again</p>
		<p class="selected"></p>
	</div>
	
	<div>
		<p>Hello Again</p>
		<p class="selected"></p>
	</div>
	
	<div>
		<p>Hello Again</p>
		<p class="selected"></p>
	</div>

I want to add text in the ‘selected’ paragraph in the second div,

<script>$("div:first").next('.selected').text("selected");</script>

it won’t work at all. please let me know if you have any ideas.

Many thanks,
Lau

I am not sure what you would like to obtain, try

$(“div:first p”).next().text(“selected”);

thanks for the idea. but it adds text in the ‘selected’ paragraph in the first div

I want to add text in the ‘selected’ paragraph in the second div though…

found this answer :slight_smile:

$(‘.selected’).eq(1).text(“selected”);