tags:

views:

24

answers:

2

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="overflow: visible; height: 40px;">
+3  A: 

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

var id = $('.searchItemSelect').attr('id');
Anzeo
now how to handle if my html merkup is stored in a variable like var mymarkup = <div id="CheckinWithUser_4" class="CheckinWithUserRow1 searchItemSelected" onclick="" style="overflow: visible; height: 40px;">
saorabh
A: 

Try .hasClass()

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

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