0

I'm wondering if that's possible to get object property from element data.

So let's say I have element:

<div data-item="objProp" class="test">test</div>

And js object:

var obj = {
objProp: true
}

I tried to:

var test = $('.test').data('item');
alert(obj.test);

So, yeah, is there any way I can do this?

2 Answers 2

2

You seem to want

alert(obj[test]);
Sign up to request clarification or add additional context in comments.

3 Comments

Yeah, thank you. For some reason I though [] only refers to arrays. Thank you once again.
I'd recommend you to read Working with objects, that's a good documentation.
You've post the answer just 8 seconds faster ;)
0

Working FIDDLE Demo

Try to use []:

alert(obj[test]);

Comments

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.