?
Solved

jquery length - count div.classname in string ?

Posted on 2014-12-03
1
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

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