First way:
jQuery('a.expandall').click(function() {...whatever...});
... defines a click for any binding element with the "expandall" class that exists anywhere in the DOM.
The second way:
jQuery('#accordionWrapper p a.expandall').click(function() {...whatever...});
... defines a click for any anchor with the class "expandall", which is a descendant of a paragraph element, which is a descendant of an element with id="accordionWrapper" . Note that the type of the "#accordionWrapper" element does not matter, since you did not specify it.
I say "element" with this id, not "element" with this id, because if your html is valid, there will be only one element with any given id. If you repeated the identifier for several elements, you will find that (for most browsers) the choice by id returns only one of these elements (most often the first).
Assuming your problem is with reusing identifiers, you can fix it by exposing several similar elements to the same class, rather than the same identifier.
source share