-3
$('a').filter(function () {
    return $(this).attr('area-expanded')
});

will return an array of links with attribute called 'area-expanded'.

I need to find a link, whose attribute 'area-expanded' value is true (there is always one such link on the page).

I tried the following:

$('a').filter(function(){return $(this).attr('area-expanded').val() == true});

but I am getting

Uncaught TypeError: Cannot read property 'val' of undefined

I'm complete noob in JS so I am sure there is something simle I am missing. Thanks!

Tushar
  • 85,780
  • 21
  • 159
  • 179
Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145

1 Answers1

3

Use attribute-value selector:

Selects elements that have the specified attribute with a value exactly equal to a certain value.

$('a[area-expanded="true"]')

This will select all the <a> whose aria-expanded attribute value is set to true.

Tushar
  • 85,780
  • 21
  • 159
  • 179