Soarabh
Soarabh

Reputation: 2950

Finding div id on the basis of its class name

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;">

Upvotes: 3

Views: 2476

Answers (2)

rahul
rahul

Reputation: 187020

Try .hasClass()

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

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

Upvotes: 0

thomaux
thomaux

Reputation: 19718

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

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

Upvotes: 6

Related Questions