0

I have got the below HTML as a response .

<div id="69" class="activateUiHTML" data-role="collapsible">
    <div class="prd-items-detials"> </div>
    <div style="" class="Topping-details" id="69">
        <section id="topping_tsection_69">
            <aside>
                <section class="secclass"><a data-id="69" topp_name="Honey with Carmel  10 ML"  class="tpActive">Honey with Carmel  10 ML</a></section>
            </aside>
            <aside>
                <section class="secclass"><a data-id="70" topp_name="Honey with Carmel  10 ML"  class="tpActive">Honey with Carmel  10 ML</a></section>
            </aside>
        </section>
    </div>
</div>

I need to find out if any section has got class as "tpActive" ??

I wrote the below , but don't know how to check further ??

$('#'+v_item_id+'.activateUiHTML').find(".Topping-details").find("section")

could anybody please help me .

Updated Question

if($('#'+v_item_id+'.activateUiHTML').find("Toppingdetails").find("section").hasClass("tpActive")) {
   alert('has');
}else {
   alert('No');
}
Siva.G ツ
  • 831
  • 1
  • 7
  • 20
Pawan
  • 31,545
  • 102
  • 256
  • 434

3 Answers3

0

jQuery already has a native .hasClass() function built if that you can add to your statement.

if ($('#topping_tsection_69').hasClass('myClass'))...

Alternatively, you could add that as part of your jQuery filtering

$('div.Topping-details')

UPDATE

You'll need to combine the two approaches to get what you're looking for.

if($('#'+v_item_id+'.activateUiHTML').find("Toppingdetails").find("section.tpActive").length > 0)

What will happen is that your .find() is returning an array of the section items from the page. You can filter your selection with the way that I included above, or you could alternatively iterate through the elements to find what you need.

krillgar
  • 12,596
  • 6
  • 50
  • 86
  • I was trying this way , updated the question – Pawan Jul 21 '14 at 15:20
  • I think that part of your problem is that your initial `$().find().find()` is returning multiple objects. You'll need to iterate over that array to find all of the elements to check with `.hasClass()`. – krillgar Jul 21 '14 at 15:22
0

You spelled it out

there's .hasClass('className') method in Jquery.

or you could use .is('.className'). whatever fits your taste.

Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265
0
if($('.activateUiHTML').find('.Topping-details').find("section").length > 0){
    alert('found');
}
MH2K9
  • 11,951
  • 7
  • 32
  • 49