?
Solved

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

Posted on 2011-10-04
13
Medium Priority
?
206 Views
Last Modified: 2012-05-12
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
Comment
Question by:areyouready344
  • 8
  • 5
13 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 36914355
alert($this).attr("id")); // should alert  list_a or list_b
0
 

Author Comment

by:areyouready344
ID: 36914388
thanks leakim
0
 

Author Comment

by:areyouready344
ID: 36914406
leakim, it says  undefined.. but $(this).index() works
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 83

Expert Comment

by:leakim971
ID: 36914418
try this one :

alert( $this).closest("ul").attr("id") ); // should alert  list_a or list_b
0
 

Author Comment

by:areyouready344
ID: 36914428
Okay I'll give it a try, alert($(this).closest.("ul").attr("id"));  
0
 

Author Comment

by:areyouready344
ID: 36914436
not working, the alert is not being fired off. alert($(this).closest.("ul").attr("id"));  
0
 
LVL 83

Expert Comment

by:leakim971
ID: 36914444
check for a typo error
0
 

Author Comment

by:areyouready344
ID: 36914491
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
 
LVL 83

Accepted Solution

by:
leakim971 earned 1000 total points
ID: 36914493
oops... better : alert($(this).closest("ul").attr("id"));
0
 

Author Comment

by:areyouready344
ID: 36914519
wow, my eyes are bad...don't have my glasses on... thanks leakim..
0
 

Author Comment

by:areyouready344
ID: 36914559
it only says, ul_a but how do I get it to say ul_b?
0
 

Author Comment

by:areyouready344
ID: 36914562
oops, i mean the alert only says #list_a, how do i get it to say #list_b
0
 
LVL 83

Expert Comment

by:leakim971
ID: 36914569
not sure...

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

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question