Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

attributes not found by jquery attribute selector

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.

like image 333
mkoryak Avatar asked Apr 13 '09 16:04

mkoryak


People also ask

What is attribute selector jQuery?

jQuery [attribute|=value] Selector The [attribute|=value] selector selects each element with a specified attribute, with a value equal to a specified string (like "en") or starting with that string followed by a hyphen (like "en-us"). Tip: This selector is often used to handle language attributes.

How to select HTML element with data attribute in CSS?

CSS [attribute^="value"] Selector The [attribute^="value"] selector is used to select elements with the specified attribute, whose value starts with the specified value.

How many Types of attributes in CSS?

The Seven Different Types. Attribute selectors are case-sensitive by default (see case-insensitive matching below), and are written inside brackets [] . There are seven different types of matches you can find with an attribute selector, and the syntax is different for each.

What is not in jQuery?

The not() is an inbuilt function in jQuery which is just opposite to the filter() method. This function will return all the element which is not matched with the selected element with the particular “id” or “class”. Syntax: $(selector).not(A) The selector is the selected element which is not to be selected.


1 Answers

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:

  • Can not select a form using the action attribute
  • attr "action" of form and Selectors' attribute filter
  • selector by attribute "src" not working the same way as in 1.2.6

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.

like image 183
Paolo Bergantino Avatar answered Sep 17 '22 16:09

Paolo Bergantino