2

If I pass a number of selectors to jQuery, how can I differentiate the selector of each of those selectors as separate strings? For example:

$('#selector-a, #selector-b, #selector-c').each(function(){
    console.log( $(this).selector ); // logs an empty string
});
4
  • 2
    Look like you actually wanted to put a class on each element and select by class. Making an id for everything isn't right. Commented Sep 9, 2011 at 16:49
  • 1
    Are you asking how you can extract the ID of a selector? Just use $(this).attr("id") for that. Commented Sep 9, 2011 at 16:50
  • var j = $('#selector-a, #selector-b, #selector-c'); and then j.selector. Commented Sep 9, 2011 at 16:52
  • stackoverflow.com/questions/5708901/… Commented Sep 9, 2011 at 16:54

1 Answer 1

1
$.each($('#selector-a, #selector-b, #selector-c').selector.split(','),
       function(index, value) {
           console.log(value);
       }
); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.