ls206 Posted October 15, 2009 Share Posted October 15, 2009 Hi, I'm looking for a way to return an element's name as a string.I can't find how to do this, is it even possible?For example... $(function() { $("img.menu").hover(function() { $(this).src = "directory/" + elementName + "_rollover.jpg"; }, function() { $(this).src = "directory/" elementName + ".jpg"; });}); Thanks for any help. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 15, 2009 Share Posted October 15, 2009 What do you mean by an element's name? Are you talking about the tag name, like "div" or "span"? If you have a name attribute on a tag you can find that in the name property of the element. Link to comment Share on other sites More sharing options...
ls206 Posted October 16, 2009 Author Share Posted October 16, 2009 Sorry I guess I wasn't very clear at all!I mean the name attribute so <img name="home_button" ...... /> for example.I'm just trying to create a JQuery rollover function that doesn't require me to call separate functions for onmouseover and onmouseout within the img tag.On a somewhat different matter, how would I cancel an effect such as fadeIn or fadeOut?e.g. $(function() { $("img.hvr").hover(function() { // Cancel any prior effects/animations of $("img.over") that may be taking place or is queued $("img.over").fadeIn("slow"); }, .....etc..}); Link to comment Share on other sites More sharing options...
jeffman Posted October 16, 2009 Share Posted October 16, 2009 I realize JQuery has a rollover function, but even so you are going about this technique in a very 1990's fashion. (An ancient concept dressed up in modern framework is still an ancient concept.) Simple image replacement is best handled using the CSS :hover attribute. It works even better if the images are sprites. (Google it.)FWIW, image elements are no longer allowed a name attribute (at least, not one that's assigned in the tag). Most elements don't have names, either. Modern names go with form inputs, frames, and 1-2 other things that don't come up a lot.I can't help you with JQuery's fadein methods. Link to comment Share on other sites More sharing options...
ls206 Posted October 17, 2009 Author Share Posted October 17, 2009 Thanks for the reply.I will have a look at CSS rollovers again as when I used CSS before it wasn't that smooth - I will look at sprites. Link to comment Share on other sites More sharing options...
chibineku Posted October 17, 2009 Share Posted October 17, 2009 The advantage of modernizing to jQuery for this idea is that the hover event has been made to work on all browsers, while the hover pseudo-class only works for anchors in IE pre ver 8. Course the users you miss from the hover attribute not working probably map pretty well onto the users who have javascript turned off. Link to comment Share on other sites More sharing options...
jeffman Posted October 17, 2009 Share Posted October 17, 2009 while the hover pseudo-class only works for anchors in IE pre ver 8.You can pick up IE 7 using a strict doctype, which you probably do anyway. If this were not the case, no one would be using the :hover pseudo-class at all. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.