Gennady Shumakher
Gennady Shumakher

Reputation: 5746

jquery v1.3.2 find element by attribute

I need to find and iterate through all child elements that have specific attribute. The following code worked fine in jquery 1.2.6, but throws exception in 1.3.2

$(parentElement).find('*[@someAttributeName]').each(function(index){
    doSomething(this);
});

What is the correct way to achieve that?

Upvotes: 26

Views: 66248

Answers (5)

tvanfosson
tvanfosson

Reputation: 532615

Just get rid of the @, I believe.

$(parentElement).find('[someAttributeName]').each(function(index){
    doSomething(this);
});

From the jQuery selector docs:

Note: In jQuery 1.3 [@attr] style selectors were removed (they were previously deprecated in jQuery 1.2). Simply remove the '@' symbol from your selectors in order to make them work again.

Upvotes: 40

Yuseferi
Yuseferi

Reputation: 8710

ithink this is the best way to find and can change something of it

   $('.youritem').each(function(){
                          if($(this).attr('title') == 'add image')
                                           $(this).attr('id','imageuploader');

                        });

Upvotes: 1

rofrol
rofrol

Reputation: 15266

Doesn't work for me in IE when I want to find inputs with required="".

Works when I change to required="required". Maybe other combinations also work https://stackoverflow.com/a/3012975/588759

Upvotes: 0

Seb
Seb

Reputation: 25157

[@attribute] notation is deprecated in jQuery 1.3. Remove the @ sign and you're good to go.

Upvotes: 2

Konstantin Tarkus
Konstantin Tarkus

Reputation: 38428

Note the "@" before the attribute name was deprecated as of version 1.2.

$(parentElement).find('*[someAttributeName]').each(function(index){
    doSomething(this);
});

Just remove it and you are good to go.

Upvotes: 2

Related Questions