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 8611689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:26:16+00:00 2026-06-12T04:26:16+00:00

I have a variable which contains an item number … like this: myvariable =

  • 0

I have a variable which contains an item number … like this:

myvariable = '3'; //Note: This is currently a string so it might need converting?

Then I have the code which populates the listview:

$('#listview').live("pageinit", function(){
$.getJSON("myjson.json", function(data){
    $.each(data.unis, function(index, value){


        $('<li><a class="listitem" href="#">' + value.name + '</a></li>').insertAfter('#' + value.sortLetter);

        $('#' + value.sortLetter).show();

    });

    $("#listview").listview("refresh");


});

All the above works fine.

Now, what I need to do it to insert a class into the item which is at the position myvariable value.

So, if myvariable is 3 then the listview will look like this:

<ul>
<li><a class="listitem" href="#">' + value.name + '</a></li>
<li><a class="listitem" href="#">' + value.name + '</a></li>
<li><a class="listitem AddedClassHere" href="#">' + value.name + '</a></li>
</ul>

if myvariable was to be 1 then:

<ul>
<li><a class="listitem AddedClassHere" href="#">' + value.name + '</a></li>
<li><a class="listitem" href="#">' + value.name + '</a></li>
<li><a class="listitem" href="#">' + value.name + '</a></li>
</ul>

and so on…

How could I do this?

  • 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-12T04:26:18+00:00Added an answer on June 12, 2026 at 4:26 am

    You can use :eq() selector, note that :eq() is zero-based.

    $('ul li:eq("'+ (myvariable-1) +'") a').addClass('class');
    

    Or:

    $('ul li').eq(myvariable-1).find('a').addClass('class');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a variable which contains function hierarchy like: string str= fun1(fun2(),fun3(fun4(fun5(34,33,'aa'),'value',fun6())) //
I have a variable which contains the value 1234567 . I would like it
I have a variable $next which contains strings that might contain parenthesis e.g trna(tgc)
I have a PHP-variable called $go_Adress which contains the adress I need to get
The variable filepath which is a string contains the value Música . I have
I have this ingredients array which contains multiple variables (like name, icon, value etc.).
I have a variable s which contains a one letter string s = 'a'
I have variable call items having array of items which contains following value [[#<Item
The scenario would be: you have a variable called person which contains a number
I have a variable which contains the following string: AL,CA,TN,VA,NY I have no control

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.