Solved

jquery length - count div.classname in string ?

Posted on 2014-12-03
1
195 Views
Last Modified: 2014-12-14
Hi
I have the following object
objmain.d[0].leftMenuDetail

Open in new window


which contains the string:
<div id='divRoute10510' class='alert_new zeroDistanceTrue' style='cursor:pointer;' onclick='ColorRoute(44280,44284,10510,860599000186460);'><div class='trip_new1'><p class='trip_textforAssetName'>GL300_TEST_AMCREST</p><p class='trip_text2'>  11:55 to  11:58<span style='float:right;'>0 miles/2 mins</span></p><p class='trip_text2'><span style='color:#175AB5;'>Clodine Road, Twin Oaks Village, US</span> to <span style='color:#175AB5;'>Clodine Road, Twin Oaks Village, US</span></p></div></div><div id='divRoute10509' class='alert_new zeroDistanceTrue' style='cursor:pointer;' onclick='ColorRoute(44273,44277,10509,860599000186460);'><div class='trip_new1'><p class='trip_textforAssetName'>GL300_TEST_AMCREST</p><p class='trip_text2'>  11:48 to  11:55<span style='float:right;'>0 miles/6 mins</span></p><p class='trip_text2'><span style='color:#175AB5;'>Clodine Road, Twin Oaks Village, US</span> to <span style='color:#175AB5;'>Clodine Road, Twin Oaks Village, US</span></p></div></div><div id='divRoute10508' class='alert_new zeroDistanceTrue' style='cursor:pointer;' onclick='ColorRoute(44266,44270,10508,860599000186460);'><div class='trip_new1'><p class='trip_textforAssetName'>GL300_TEST_AMCREST</p><p class='trip_text2'>  11:47 to  11:48<span style='float:right;'>0 miles/1 min</span></p><p class='trip_text2'><span style='color:#175AB5;'>Clodine Road, Twin Oaks Village, US</span> to <span style='color:#175AB5;'>Clodine Road, Twin Oaks Village, US</span></p></div></div><div id='divRoute10507' class='alert_new ' style='cursor:pointer;' onclick='ColorRoute(44242,44263,10507,860599000186460);'><div class='trip_new1'><p class='trip_textforAssetName'>GL300_TEST_AMCREST</p><p class='trip_text2'>  11:29 to  11:47<span style='float:right;'>0.7 miles/17 mins</span></p><p class='trip_text2'><span style='color:#175AB5;'>Taraglen Court, Twin Oaks Village, US</span> to <span style='color:#175AB5;'>Clodine Road, Twin Oaks Village, US</span></p></div></div><div id='divRoute10506' class='alert_new zeroDistanceTrue' style='cursor:pointer;' onclick='ColorRoute(44236,44239,10506,860599000186460);'><div class='trip_new1'><p class='trip_textforAssetName'>GL300_TEST_AMCREST</p><p class='trip_text2'>  11:24 to  11:29<span style='float:right;'>0 miles/4 mins</span></p><p class='trip_text2'><span style='color:#175AB5;'>Taraglen Court, Twin Oaks Village, US</span> to <span style='color:#175AB5;'>Taraglen Court, Twin Oaks Village, US</span></p></div></div><div id='divRoute10505' class='alert_new zeroDistanceTrue' style='cursor:pointer;' onclick='ColorRoute(44228,44232,10505,860599000186460);'><div class='trip_new1'><p class='trip_textforAssetName'>GL300_TEST_AMCREST</p><p class='trip_text2'>  11:16 to  11:17<span style='float:right;'>0 miles/1 min</span></p><p class='trip_text2'><span style='color:#175AB5;'>Taraglen Court, Twin Oaks Village, US</span> to <span style='color:#175AB5;'>Taraglen Court, Twin Oaks Village, US</span></p></div></div><div id='divRoute10504' class='alert_new zeroDistanceTrue' style='cursor:pointer;' onclick='ColorRoute(44221,44225,10504,860599000186460);'><div class='trip_new1'><p class='trip_textforAssetName'>GL300_TEST_AMCREST</p><p class='trip_text2'>  11:11 to  11:16<span style='float:right;'>0 miles/4 mins</span></p><p class='trip_text2'><span style='color:#175AB5;'>Taraglen Court, Twin Oaks Village, US</span> to <span style='color:#175AB5;'>Taraglen Court, Twin Oaks Village, US</span></p></div></div>

Open in new window


I need to search this HTML for instances of a DIV that has a class called
.zeroDistanceTrue

Open in new window


I've tried this code
$('.zeroDistanceTrue', objmain.d[0].leftMenuDetail).length;

Open in new window


But it comes back as 0

When i look in chrome dev toolbar is see:
Capture.PNG
what code do i need to get the COUNT of Div's with the class name zeroDistanceTrue ?
0
Comment
Question by:websss
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40478600
Try this first :
$('.zeroDistanceTrue').length;

if you still get zero... that mean the class name is wrong or not in the current document (not yet loaded for ajax or document ready reason)

Try this too :
$('.zeroDistanceTrue', $(objmain.d[0].leftMenuDetail)).length;
or this (I think this is your answer) :
$('.zeroDistanceTrue', $(objmain.d[0].leftMenuDetail).parent()).length;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now