Reputation: 2297
How to select an element along with $(this)
?
I know selecting more than one element is possible in jQuery by separating them with a comma(,).
For e.g. we can select two ids, say "element1" and "element2" as:
$("#element1,#element2")
However, I'm not able to select more than one element if one of them is $(this), i.e. I can't select $(this) and $("#element") simultaneously in a single selection. How do I achieve this?
Upvotes: 2
Views: 114
Reputation: 685
If you select any element in jQuery you create array. Even if you select one element:
var id = jQuery("#my-id");
console.log(id); // [element]
so You can do something like this:
jQuery(document).ready(function(){
jQuery("a").on("click", function(){
var allElements = jQuery("div");
allElements.push(this);
console.log(allElements)
});
});
Upvotes: 0