I have a jQuery code as follows;
var favorites = $("#favorites");
var favoritesFooter = $("#favoritesFooter",favorites);
I am not sure what does the comma mean in the 2nd statement $("#favoritesFooter",favorites);
Also what would the following statement do or represent in the above case;
favoritesFooter.prev().after(newHTML);
The second statement means "search for element with ID of
favoritesFooter
inside the jQuery objectfavorites
".As you're dealing with ID which should be unique, it's pointless -
$("#favoritesFooter")
is the best practice.RegardingfavoritesFooter.prev()
it's also pointless, assuming the ID is unique so you have collection with only one element thusprev()
will return empty jQuery collection.The
.prev()
will take the previous DOM element - in your case, it will pushnewHTML
right before thefavoritesFooter
element.It's the second parameter to
$()
. As explained in the documentation: