Link to home
Start Free TrialLog in
Avatar of areyouready344
areyouready344Flag for United States of America

asked on

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());
    {
});
Avatar of leakim971
leakim971
Flag of Guadeloupe image

alert($this).attr("id")); // should alert  list_a or list_b
Avatar of areyouready344

ASKER

thanks leakim
leakim, it says  undefined.. but $(this).index() works
try this one :

alert( $this).closest("ul").attr("id") ); // should alert  list_a or list_b
Okay I'll give it a try, alert($(this).closest.("ul").attr("id"));  
not working, the alert is not being fired off. alert($(this).closest.("ul").attr("id"));  
check for a typo error
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"));      
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
wow, my eyes are bad...don't have my glasses on... thanks leakim..
it only says, ul_a but how do I get it to say ul_b?
oops, i mean the alert only says #list_a, how do i get it to say #list_b
not sure...

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