I’m trying to extract an id from an object.
The object data.prevPage[0].attributes returns this:
[ data-show="first"
, id="brandlist"
, data-role="page"
, data-url="brandlist"
, data-dom-cache="true"
, class="ui-page-active ui-page ui-body-c"
, tabindex="0"
, style="min-height: 927px; margin-left: 250px; width: 671px;"
]
If I console console.log( data.prevPage[0].attributes.id ) I’m getting
id="brandlist"
Question:
How do I get brandlist only? Something like data.prevPage[0].attributes[id] doesn’t work.
Thanks
EDIT:
So, going with the answer given:
var test = data.prevPage[0].attributes.id,
el = $('#'+test)
produces the following error:
Error: Syntax error, unrecognized expression: #[object Attr]
which tells me, the console does return id=”brandlist” and not brandlist….
you allready did use the correct answer when you typed it in the console. It is: