thelinh bui
thelinh bui

Reputation: 226

select element in JQuery

Hi would you please help how can i extract "Men" text in this case?

<div class="comwebstore-LeftNavBrowse-2">
    <ul class="linkList browseLadder">
       <li>
           <a href="example.com"> Men </a>
       </li>
       <ul class="linkList browseLadder">
         <li>
            <a href="example.com"> Full Logo T-Shirt </a>
         </li>
         <li>
            <a href="example.com"> Short Logo T-Shirt </a>
         </li>
         <li>
            <a href="example.com"> Grey Hoodie 1 Full Logo </a>
         </li>
         <li>
           <a href="example.com"> Grey Hoodie 2 Short Logo </a>
         </li>
         <li>
            <a href="example.com"> Women </a>
         </li>
         <li>
            <a href="example.com"> Accessories </a>
         </li>
       </ul>
     </ul>
  </div>
</div>

I have tried

jQuery('#mainContentWrapper #leftColumn #A #A-1 .com-amazon-webstore-LeftNavBrowse-2 > :first-child a').text();

but without succeed. Thanks

Upvotes: 0

Views: 57

Answers (2)

Vinayak Phal
Vinayak Phal

Reputation: 8919

Check your selector...<div class="comwebstore-LeftNavBrowse-2"> You have comwebstore-LeftNavBrowse-2 class and you're using .com-amazon-webstore-LeftNavBrowse-2

Please dont use such a long selectors. This will reduce your selectors performance and it looks ugly. Just check what Alex Ball has suggested.

jQuery('#mainContentWrapper #leftColumn #A #A-1 .comwebstore-LeftNavBrowse-2 > :first-child a').text();

Upvotes: 0

Alex Ball
Alex Ball

Reputation: 4484

From your html:

alert($('.linkList > li:first a').text());

Upvotes: 1

Related Questions