开发者

Finding div id on the basis of its class name

开发者 https://www.devze.com 2023-01-21 10:22 出处:网络
I have to find div id on the basis of its class, if the div have class named searchItemSelected, then how to get its div id.

I have to find div id on the basis of its class, if the div have class named searchItemSelected, then how to get its div id.

<div id="CheckinWithUser_4" class="CheckinWithUserRow1 searchItemSelected" onclick="" style="overflo开发者_StackOverflow社区w: visible; height: 40px;">


All attributes of an element can be accessed through the .attr() method:

var id = $('.searchItemSelect').attr('id');


Try .hasClass()

var mymarkup = '<div id="CheckinWithUser_4" class="CheckinWithUserRow1 searchItemSelected" onclick="" style="overflow: visible; height: 40px;">';

if ($(mymarkup).hasClass("searchItemSelected")) 
{
    alert(this.id);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消