2010/03/12

name attribute of <a> tag

There are several attributes of <a> tag, and ‘name’ is one of them. I just found today, that you cannot have character, ‘%’, as a value of this attribute.

I used to use name attribute to hold some data, then pass it as variable in jQuery code as the following,

$(document).ready(function() {
  $(".s-img>a").hover(function(){
    var largePath = $(this).attr("name"); 
    // note: here I used 'name' attr 
    $("#limg").attr({ src: largePath});
    return false;
    },
    function() {
      ;
  });
});

It failed when the name has ‘%’ character in there. Fortunately, the “alt” attribute is happy with ‘%’as its value. So then, changed it ‘alt’, it works.

P.S. Actually, I see most of ‘alt’ other than ‘name’ to pass variable. Maybe, this is a reason.

No comments:

Post a Comment