(Edited with more detail just in case someone else has a similar question)
I’ve got an image map which needs to reveal a div on rollover of a hotspot. I’ve given my areas on the image map classes, and using jQuery want to reveal it’s corresponding div, e.g.,
area shape="rect" coords="601,31,723,107" href="#" alt="Some Location" class="some-location"
Each area has a different location and therefore different classname.
I’m not sure how to reference an element with its classname stored in a variable?
For example, the code I currently have to get the class name on hovering over an area on the image map is:
var hotspot = $(this).attr("class");
Now I want to do something like:
$(div.hotspot).show();
The above is not working – could someone point me in the right direction?
Use string concatenation:
Obviously this only works if
hotspotonly contains one class (see Reigel’s comment). If it contains more classes, you have to replace the white spaces by a dot:(assuming that multiple white spaces between class names get trimmed automatically but I am not sure about that, otherwise you have to use the regular expression
/\s+/)