1

I need your help in this topic i have the html code :

<ul data-role="rows">
<li data-name="member">member X</li>
<li data-name="question">question X</li>
</ul>
<ul data-role="other">
<li data-name="oth">...</li>
...
</ul>

I need to get data-name values where data-role = rows which means i need to get these values : "member" and "question"

thank you for your help

1 Answer 1

2

Just target those elements, and map back the data attributes

var names = $('[data-role=rows] [data-name]').map(function(_,el){
    return $(el).data('name');
}).get();

FIDDLE

Sign up to request clarification or add additional context in comments.

1 Comment

it returned this in the console when i tried to log "names" : [prevObject: b.fn.b.init[8], context: document]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.