I am new to Jquery and CSS . I am trying to add li elements based on some condition in JSP -for loop as below:
<ul id="my-criteria-list" >
<%
for( int i = 0 ; i < mychoices.length ; i++ )
{
if( i > 0 )
{
%>
<li class="divider">|</li>
<%
}%>
<li class="my-criteria"><a href="Landing Page" onclick="goTo(this);"><%=mychoices[i])%></a></li>
<%
}
%>
</ul>
MyChoices length is 4 and JSP page display all li elements correctly. But when I do
$('li a:first-child').trigger('click');
or even
$('li a:nth-child(1)').trigger('click');
only last element is selected. So that means there is only one element in <LI>? I need to trigger click for first <LI> element. Any help /suggestions ?
Your code is selecting the first child
ainstead a parentli. What you want to do is select the first childliinside parentulinstead, and then select and click theainside that.Try this: