How to retrieve class element from a haml document
Question
I am trying to access the DOM element for 'show more topics' from the haml file
#profile-wrapper.container-fluid
.sidebar
.profile
%h4 Interests
%ul.topics
%a.show_more_topics.hide Show More
I tried to run the following code:
$('.topics .show_more_topics')
However I am getting back an empty array [].
How can I retrieve the 'show more topics' element?
Solution
The link with class show_more_topics
is a sibling of the topics
list (see how they're indented the same?), while the selector .topics .show_more_topics
selects an element with the class show_more_topics
that's a descendent of an element with the class topics
.
You just want $('.show_more_topics')
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow