Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery v1.3.2 find element by attribute

Tags:

jquery

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?

like image 678
Gennady Shumakher Avatar asked Mar 30 '09 12:03

Gennady Shumakher


4 Answers

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.

like image 136
tvanfosson Avatar answered Nov 08 '22 04:11

tvanfosson


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.

like image 33
Konstantin Tarkus Avatar answered Nov 08 '22 06:11

Konstantin Tarkus


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

like image 2
Seb Avatar answered Nov 08 '22 05:11

Seb


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');

                        });
like image 1
Yuseferi Avatar answered Nov 08 '22 04:11

Yuseferi