Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8150959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:13:10+00:00 2026-06-06T15:13:10+00:00

i have this lists, and i want select li element from jquery when the

  • 0

i have this lists, and i want select li element from jquery when the link is click

<ul>
    <li><a class="accordion" href="#">1</a></li>    
    <li><a class="accordion" href="#">2</a></li>    
    <li><a class="accordion" href="#">3</a></li>    
    <li><a class="accordion" href="#">4</a></li>    
    <li><a class="accordion" href="#">5</a></li>    
    <li><a class="accordion" href="#">6</a></li>    
</ul>

i write this jquery code

 $('a.accordion').click(function() {
      var href = $(this).attr("href");
      div = $('<div/>', {
         id: 'intotheli',
         style: {width:200}
      });
      //console.log(div);

      // loading content  with ajax custom function  
      div.html( loadcontent(div,$(this).attr("href"))); 
      // on this point i want find the li tag that contain the clicked link
      div.slideDown('slow').appendTo($(this));                  

      return false;
});

i have tried with .next() and prev() from $(this) but i don’t resolve my issue (maybe i used them wrong )

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:13:12+00:00Added an answer on June 6, 2026 at 3:13 pm

    As it looks like you are new to this, here’s how I’d rewrite this:

    <ul class="accordion">
        <li><a href="#">1</a></li>    
        <li><a href="#">2</a></li>    
        <li><a href="#">3</a></li>    
        <li><a href="#">4</a></li>    
        <li><a href="#">5</a></li>    
        <li><a href="#">6</a></li>    
    </ul>
    

    This makes the markup smaller and tidier.

    Then instead of:

    $('a.accordion').click(function() {
    

    I’d use:

    $('.accordion').on("click", "a", function() {
    

    This means only one eventhandler is bound, rather than 6, speeding things up a little, but again just keeping things simple. This change only works with my new markup.

    The rest of your code will work as is, $(this) still refers to the clicked link.

    To get the li element that the a is in, you use $(this).parent('li').

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several unordered lists that I want to display like this: <ul> <li><img></li>
I have code that I want to look like this: List<Type> Os; ... foreach
I have List of particular class. I want to save this List at a
I have a jquery mobile list. This list is populated with data. I want
I have a situation where i want to return List<> from this function public
I have a table generated from some PHP code that lists a SMALL amount
I want to do something like this, but in python : select * from
I want to add about 150 element from a xml file to a select
I have the following html element <select id=selectStates size=5 multiple=multiple class=box> <option value=tx>Texas</option> <option
I have this IEnumerable: var collection = from obj in list select new {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.