Solved

jquery length - count div.classname in string ?

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

743 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

13 Experts available now in Live!

Get 1:1 Help Now