Pawan
Pawan

Reputation: 32321

Unable to find the length of a element having a class .

I have got the following HTML Response .

I am trying to check , under the activateUiHTML div if the section id named topping_tsection_69 has got any section elements with class as "tpActive"

<div id="69" class="activateUiHTML" data-role="collapsible">
   <div class="prd-items-detials">
      <ul>
         <li class="head">
            <form> <input type="checkbox" class="checkboxclas" name="checkbox-mini-0" id="69" data-mini="true" id_attr="69"><label item_id_itr_some="69" class="testtt" for="checkbox-mini-0">Cold Tea, Fresh Chai gold Ice </label><i class="delete-item-btn"></i></form>
         </li>
      </ul>
   </div>
   <div style="" class="Topping-details" id="69">
      <section id="topping_tsection_69">
         <aside>
            <h6 class="tdHeading">Quantity      1</h6>
            <img src="images/arrow-topping.png">
            <section class="secclass"><a data-id="69" topping_id="17" id="69_ZZ_0_ZZ_0" topp_name="Honey with Carmel  10 ML" top_price="30" class="tpActive" qt_val="69_ZZ_0_ZZ_0">Honey with Carmel  10 ML</a></section>
         </aside>
         <aside>
            <h6 class="tdHeading">Quantity      1</h6>
            <img src="images/arrow-topping.png">
            <section class="secclass"><a data-id="69" topping_id="17" id="69_ZZ_0_ZZ_0" topp_name="Honey with Carmel  10 ML" top_price="30" class="tpActive" qt_val="69_ZZ_0_ZZ_0">Honey with Carmel  10 ML</a></section>
         </aside>
      </section>
   </div>
</div>

This is my jsfiddle

http://jsfiddle.net/HupC8/

This is the way i tried

var id = 69 ;
var aaa =$('#'+id+'.activateUiHTML').find("#topping_tsection_"+id+".secclass").find("a.tpActive").length;

But always it returns 0 .

Could anybody please help me how to resolve this .

Upvotes: 0

Views: 43

Answers (2)

Irvin Dominin
Irvin Dominin

Reputation: 30993

I hope it's a sample code, because you have multiple elements with the same id attribute.

I think you are missing a space in the selector the section with class secclass is a child of topping_tsection_<id> element.

Code:

var aaa = $('#' + id + '.activateUiHTML').find("#topping_tsection_" + id + " .secclass").find("a.tpActive").length;

Demo: http://jsfiddle.net/56RFM/

Upvotes: 0

Dhaval Panchal
Dhaval Panchal

Reputation: 648

Try ths

var id = 69 ;
var aaa =$('#'+id+'.activateUiHTML').find("#topping_tsection_"+id+" .secclass").find("a.tpActive").length;

Upvotes: 1

Related Questions