in which element is currently the class '.bar' ? Here is another solution but it's up to you.
var reg = /Image/g, // regexp for an image element
query = document.querySelector('.bar'); // returns [object HTMLImageElement]
query += this.toString(); // turns object into a string
if (query.match(reg)) { // checks if it matches
alert('the class .bar is attached to the following Element:\n' + query);
}
Of course this is only a lookup for 1 simple element <img>
(/Image/g
) but you can put all in an array like <li>
is /LI/g
, <ul>
= /UL/g
etc.