Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
189
rated 0 times [  194] [ 5]  / answers: 1 / hits: 90001  / 9 Years ago, sat, august 1, 2015, 12:00:00

I didn't find a way to get aria-expanded value from DOM.



<a class=accordion-toggle collapsed href=#collapse-One data-parent=#accordion-1 data-toggle=collapse aria-expanded=false>
<i class=fa fa-search-plus></i>
test
</a>


I want to test if it's true then I can change <i> class to fa-search-minus. I tried this but I always get an undefined value:



console.log($(this).find('a.aria-expanded').val());

More From » jquery

 Answers
9

aria-expanded is an attribute on the element, not a class, so the selector is incorrect. Secondly, you should use the attr() function to get the value of that attribute. val() is intended to retrieve the value attribute from form related elements, such as input and textarea. Try this:



console.log($(this).find('a[aria-expanded]').attr('aria-expanded'));

[#65578] Thursday, July 30, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aileent

Total Points: 556
Total Questions: 107
Total Answers: 101

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;