To select only the <g>
tags that contain a rect with classes "with_href" and "selected", you can do the following:
document.querySelectorAll('g > rect.with_href.selected')
That would return an array.
You could compare that array to the array returned by this:
document.querySelectorAll('g')
And if the length of the first array is less than the length of the second, you can alert the user, since not all of the g tags contain the rect with the two classes.