I have a line of jQuery code that is causing an error as I placed two periods in front of the b class. I am wondering how does jQuery interpret the following line? If I had only one period in front of b instead of two, I assume that jQuery interpret it as: “if class b exists within class a which exists in the parent of this, alert prompt hi”.
if ( $(this).parent().find(".a ..b") ) {
alert("hi");
});
.a ..bis an invalid selector and it will throw error:.a .bis the correct selector.So
$(this).parent().find(".a .b")will first fetch the direct parent node ofthis, then it will search for a descendant element with theclass="a"and then another descendant element within with theclass="b", and if it finds it will alerthi.