So I am using attr("alt") inside the "success" block in jQuery Validation plugin. However, attr("alt") returns undefined even though the attribute ("alt") is definitely defined.
Here's my code:
$(this).validate({
success: function(label) {
var api = $('#' + label.attr("for")).qtip("api");
api.updateContent($('#' + label.attr("for")).attr("alt"), true);
}
})
So label.attr("for")
works just fine and returns the id of the target input field. However, when I plug that in to $('#' + label.attr("for)).attr("alt")
, it returns undefined even though the alt attribute is defined. Am I missing something or is this something that happens with the jQuery Validation plugin (maybe it removes the alt attribute on-the-fly without me knowing about it?)
Help is greatly appreciated!!!
EDIT: In fact $('#' + label.attr("for")).attr("id")
and attr("name")
both work as expected too. So it seems it's specifically attr("alt")
that isn't working. Could qTip be doing something funky (since I think it takes alt as default value for tooltip content)?
UPDATE: More baffling yet... $('#' + label.attr("for")).attr("alt")
DOES NOT WORK, but $('#' + label.attr("for"))[0].alt
DOES WORK. I'm just gonna use that as a solution, but does anyone know WHY???