While hacking my free-time project I stumbled upon a puzzling jQuery behaviour.
I have a custom validation plugin written and working. In the plugin I wanted to implement some functionality using .closest() method. Strangely enough this method returns multiple elements.
Here is a sample code:
this.closest(".control-group")
$(this).closest(".control-group");
Both above code lines select all four elements with class "control-group". This code put inside my plugin works:
var element_ID = this.attr("id");
$("#" + element_ID).closest(".control-group")
Above selects the correct and only one element with "control-group" class.
I can't use this "hack" as not all elements that I want to validate have "id" property set, so it won't work in all cases.
Using jQuery 1.7.2 (seems to be latest stable). Any ideas why it's like that?