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

  • Home
  • SEARCH
  • 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 9259419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:39:14+00:00 2026-06-18T12:39:14+00:00

I have the following code in jQuery Mobile : <ul data-role=listview data-theme=d id=#listview data-divider-theme=d>

  • 0

I have the following code in jQuery Mobile :

<ul data-role="listview" data-theme="d" id="#listview" data-divider-theme="d">
    <li data-role="list-divider" class="name">Mr. Sam</li>
            <li data-icon="false" class="details">
                       <a onclick="getInfo()">

And on my onclick, I want to access the Mr. Sam. Here’s the following code I’m trying in the JS:

var info = $(this).parent().parent().text();

Because, I’m clicking on <a>, it’s parent is <li>, and it’s parent is <li> containing Mr. Sam. But I’m doing something wrong, as alert(info); alerts a blank output.
What do I need to change? I’ve even tried, .html().

  • 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-18T12:39:15+00:00Added an answer on June 18, 2026 at 12:39 pm

    In your markup the target li is not grand-parent of the clicked element, it’s previous sibling of the parent element:

    <li data-role="list-divider" class="name">Mr. Sam</li>
                                                   ---^
    

    You can use prev method:

    var info = $(this).parent().prev().text(); 
    

    Also note that in your code this refers to window object, you can pass this to your function:

    <a onclick="getInfo(this)">
    

    function getInfo(elem) {
       var info = $(elem).parent().prev().text(); 
    }
    

    http://jsfiddle.net/F8wt8/

    Since you are using jQuery (after removing # from uls ID attribute) instead of onclick attribute you can use click method.

    $('#listview li.details a').click(function(event){
       event.preventDefault();
       var info = $(this).parent().prev().text();
       // console.log(info);
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jquery mobile code: <div data-role=collapsible> <h3>I like to read a
I have the following code for a jquery mobile page. When I run it
I have the following jquery code: $(document).ready(function() { $(body[class*=page-calendar-practices] #content-header h1#title).after(<div id='athletics_practice-schedule'><div id='inner-title'><a href='www.example.com'
I have the following code jQuery.getJSON(encodeURI(strUrl), {address:address,state:state, zip:zip},function(data){ alert('HELLO World!'); }); If for some
I have a login page using jQuery Mobile which contains the following code: <div
I am using jQuery Mobile for the first time. I have the following code:
I have a jQuery listview and the following code to change it into an
I have the following jQuery Code: $(#menu span).click(function() { var url = this.getAttribute(data-url); var
I have a jquery mobile page that uses the following code to hide a
I have the following code: <div data-role=page id=Page1 > <!-- Footer here --> <div

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.