[EMAIL PROTECTED] wrote:
Well bad example, I will not be using it will the id attribute, and I
will be getting more the one results, so $().attr() will not work.

On Jul 10, 3:41 am, Klaus Hartl <[EMAIL PROTECTED]> wrote:
[EMAIL PROTECTED] wrote:
with something like..
<img id="banner" alt="This is a banner" />
//[EMAIL PROTECTED]'banner']/@alt would return "This is a banner". Doing it this
way does not work, but is valid in 
XPatherhttps://addons.mozilla.org/en-US/firefox/addon/1192
Is there another way to do this in JQuery (I am currently just looping
the return and extracting the attribute if set)?
jQuery supports (some) XPath for selecting things, but not the whole
Spec. Try:

var alt = $('#banner').attr('alt');

Looping is pointless because an id is supposed to be unique in a
document. Also I think the CSS selector syntax should be faster then
your generic approach.

--Klaus



Ok, say you want an array that gathers all the alt attributes of the matched elements, you can use the $.map method:

var altAttrs = $.map( $('img'), function() { return this.alt; } );


--Klaus

Reply via email to