views:

3405

answers:

2

I need to reask my old question, I probably shouldnt have asked it at 1am :P

It seems that some attributes are not being found using jquery's attribute selector:

$("*[some=value]");

So far it seems that i cant use form's action attribute, and img's src attribute. Is there a list somewhere of attributes that do not work so i can write custom selectors for them?

Thanks again!


Edit: No one seems to believe that some selectors do not work as expected. Look at this example: On this site (which has jquery 1.3 on it for firebugging) there is a form that looks like this:

<form style="display: inline;" method="get" action="list">

(its around the 'search current downloads' dropdown). If you open firebug and try this selector:

$("form[action=list]");

you will NOT be able to select the form. There is nothing special about the action attribute. Same goes for the src of the logo image on that page:

<img alt="Logo" src="/p/aost/logo?logo_id=1238551994"/>

The selector which does not work is:

$("img[src=/p/aost/logo?logo_id=1238551994");

Sure, i can do wildcard matches, that is not what i am after.

+3  A: 

It all depends on which jQuery version you're using.

Before 1.3, you could use @ notation:

$("*[@name=value]")

So maybe adding @ helps.

Other than that, you should enter the attribute value exactly the same as it's defined in the markup - e.g. if you're trying to find an image with src="http://example.com/dog.jpg", don't do this because it won't work:

$("img[src=dog.jpg")

as it will be trying to find images with src equal to "dog.jpg", not containing it.

If you want to search attributes defining only parts of it, I'd suggest reading the jQuery API Selectors page. For example, to get all images whit src containing "dog.jpg", you could use:

$("img[src*=dog.jpg]")

Similarly, you can find elements whose attributes start or end with specific values / strings.

Seb
+9  A: 

There is no "list" of unsupported attributes because there shouldn't be; this is a bug in jQuery.

Here are the open tickets on this:

Apparently the common denominator between the bugs is that jQuery is comparing the selector string you specify against the full URL as opposed to the actual action/src attribute as it is defined in the HTML. This explains why the attributeEndsWith or the attributeContains selectors do work in this case.

I would recommend just giving the form/image a class/ID and getting it over with.

Paolo Bergantino
Thanks, this is the info i was looking for
mkoryak