Attributes not found using jquery attribute selector

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

It seems that some attributes were not found using the jquery attribute selector:

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

So far it seems that I cannot use the action action attribute and the img src attribute. Is there a list somewhere of the attributes that do not work, so I can write special selectors for them?

Thanks again!


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

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

(around the Search Current Downloads drop-down list). If you open Firebug and try this selector:

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

You cannot select a form. There is nothing special about the action attribute. The same applies to the src logo image on this page:

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

A selector that does not work:

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

Of course, I can do wildcard matches, this is not what I want.

+6
jquery css-selectors css3 attributes
source share
2 answers

There is no β€œlist” of unsupported attributes, because there should not be; this is a bug in jQuery.

Here are the open tickets to this:

Apparently, the common denominator between the errors is that jQuery compares the specified selector string with the full URL, and not the actual action / src attribute as defined in HTML. This explains why attributeEndsWith or attributeContains selectors work in this case.

I would recommend just specifying the form / image of the class / ID and getting it with.

+11
source share

It all depends on which version of jQuery you are using.

Prior to version 1.3, you can use @notation:

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

So maybe adding @ helps.

In addition, you must enter the attribute value in the same way as it is defined in the markup - for example. if you are trying to find an image with src="http://example.com/dog.jpg" , do not do this because it will not work:

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

as he will try to find images with src equal to "dog.jpg" not containing it.

If you want to look for attributes that define only parts of it, I would suggest reading the jQuery API Selectors page. For example, to get all src images containing "dog.jpg", you can use:

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

Similarly, you can find elements whose attributes begin or end with specific values ​​/ lines.

+4
source share

All Articles