Solved

jquery length - count div.classname in string ?

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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

690 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