简体   繁体   中英

Select tag and class and get custom attribute

I'm trying to get a custom attribute using jquery and also select it, but i'm having a bit of trouble with it

Here is my jquery code to select the value

var stockId = $("tr .ui-state-highlight").select("[id]").val();

here is the tag i'm trying to select

<tr role="row" id="2" tabindex="0" class="ui-widget-content jqgrow ui-row-ltr ui-state-
highlight" aria-selected="true"><td role="gridcell" style="text-align:left;" 
title="Alkaline Batteries" aria-describedby="productSetsSearchList-data_Name">Alkaline 
Batteries</td><td role="gridcell" style="text-align:left;" title="Alkaline Batteries" 
aria-describedby="productSetsSearchList-data_Title">Alkaline Batteries</td></tr>

Can anyone see what I am doing wrong to select the the tr with class ui-state-highlight and then gather the custom attribute ID

您需要使用组合的选择器tr.ui-state-highlight来找到类ui-state-highlight tr ,然后使用.attr()获得所需的属性值

var stockId = $("tr.ui-state-highlight").attr("id");

try

var stockId = $("tr.ui-state-highlight").attr("id");

or

var stockId = $("tr.ui-state-highlight").attr("your custom attribute");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM