• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

how to determine if $(this) is for list_a or list_b?

how to determine if $(this) variable is for list_a or list_b from the following example code? If the $(this) is for list_b, how do I set for list_a at that point in the code?

$('#list_a li') .gt(' + counter +').each(function()
{
    if(textWidth < totalWidth)
    {
           $('#list_b li').append('<li>' +  textValue +   '</li>')          
           alert($this).index());
    {
});
0
areyouready344
Asked:
areyouready344
  • 8
  • 5
1 Solution
 
leakim971PluritechnicianCommented:
alert($this).attr("id")); // should alert  list_a or list_b
0
 
areyouready344Author Commented:
thanks leakim
0
 
areyouready344Author Commented:
leakim, it says  undefined.. but $(this).index() works
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
leakim971PluritechnicianCommented:
try this one :

alert( $this).closest("ul").attr("id") ); // should alert  list_a or list_b
0
 
areyouready344Author Commented:
Okay I'll give it a try, alert($(this).closest.("ul").attr("id"));  
0
 
areyouready344Author Commented:
not working, the alert is not being fired off. alert($(this).closest.("ul").attr("id"));  
0
 
leakim971PluritechnicianCommented:
check for a typo error
0
 
areyouready344Author Commented:
the code works at the first index and then stop without generating the alert,

does this code look correct, alert($(this).closest.("ul").attr("id"));      
0
 
leakim971PluritechnicianCommented:
oops... better : alert($(this).closest("ul").attr("id"));
0
 
areyouready344Author Commented:
wow, my eyes are bad...don't have my glasses on... thanks leakim..
0
 
areyouready344Author Commented:
it only says, ul_a but how do I get it to say ul_b?
0
 
areyouready344Author Commented:
oops, i mean the alert only says #list_a, how do i get it to say #list_b
0
 
leakim971PluritechnicianCommented:
not sure...

$('#list_a li,#list_b li').gt(' + counter +').each(function()

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now