Solved

jquery length - count div.classname in string ?

Posted on 2014-12-03
1
198 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Web forms being filled out by bots 4 34
Best Way to remove the port from a URL? 15 37
Optimize simple Javascript code to use no repetitions 12 31
innerHTML 7 19
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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…

777 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