I'm trying to find element with jQuery by its data attribute value. The problem is, that the value is object and find() function doesn't work properly for me...
Data attribute value looks like this:
<tr class="odd" data-row="{"id_construction":2,"created_date":2015-11-30}">
And here is my script:
for(var i = 0; i < dataList.length; ++i){
var constructionId = dataList[i].id_construction;
if (constructionId == selectedConstructionId) {
$('.gridator').find('tr[data-row={id_construction:}').addClass('selected-construction');
}
}
value of dataList[i] is {"id_construction":2,"created_date":2015-11-30}
How should I edit this script to find the wanted element? (Element which data-row value is equal to dataList[i] value)
Fiddle: https://jsfiddle.net/og1j1wc3/4/
find the wanted element?data-rowvalue is equal todataList[i]valuedata-row='{"id_construction":2,"created_date":2015-11-30}'on yourtrsince your data-row would return only a{$('.gridator').find('tr[data-row='+dataList[i]+']')since tr has the attribute you are selectingError: Syntax error, unrecognized expression: tr[data-row=[object Object]]