Jump to content

Return Element Name As A String, Can It Be Done?


ls206
 Share

Recommended Posts

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

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

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...