How to access a <ul> list element in jQuery?

there. I have a div with a list of links in it and I'm trying to store one of the links in a jquery variable, but I'm not sure how to reach it. Unfortunately I can edit the divs or lists directly to add ids (its a yahoo store site), so i need to traverse the object tree.

Here's my practice code

   <div id="newDiv">
        <div id="newerDiv">
            <div id= "squareDiv" style="width: 100px; border:2px solid #a1a1a1;" >Square
                <li><a title="Inca" href="mainazag.html">Maya Inca Aztec</a> </li>
                <li><a title="Maya" href="mainazag.html">Maya Inca Aztec</a> </li>

and this is what I was trying to do access the link with title Maya:

var listitem = $("#squareDiv").find("a[title='Maya']");

any ideas?



the ul is not a descendant of #squareDiv, it is the next sibling. Also the anchor element does not have a class called a so the class selector will not work, you need to use element selector

var listitem = $("#squareDiv").next().find("a[title='Maya']");

Demo: Fiddle

or use the parent div id newerDiv whose child is the ul element

var listitem = $("#newerDiv").find("a[title='Maya']");

Demo: Fiddle

Need Your Help

TRibbon's large button's image is not centered...any ideas? easy to demonstrate at design-time

delphi delphi-2009 ribbon-control

i'm using delphi 2009 (updates 1, 2, 3, 4). i'm seeing something quite peculiar. the image on the button is not centered in the button when i have a large button with a large glyph! rather than ...

Replacing characters in a string with another string

c# string linq

So what I am trying to do is as follows :