var myHTML = '<div class="mapInfoWindow"><p class="infoWindowParagraph">DATA HERE</p><p class="infoWindowParagraph">DATA HERE</p><p class="infoWindowParagraph">DATA HERE</p><p class="infoWindowParagraph">DATA HERE</p></div><div class="mapInfoWindow"><p class="infoWindowParagraph">DATA HERE</p><p class="infoWindowParagraph">DATA HERE</p><p class="infoWindowParagraph">DATA HERE</p><p class="infoWindowParagraph">DATA HERE</p></div><div class="mapInfoWindow"><p class="infoWindowParagraph">DATA HERE</p><p class="infoWindowParagraph">DATA HERE</p><p class="infoWindowParagraph">DATA HERE</p><p class="infoWindowParagraph">DATA HERE</p></div>';
var obj = $(myHTML).get(0);
var totalCount = $(obj).find('.infoWindowParagraph').length;
console.log('Total p.infoWindowParagraph tags in the FIRST mapInfoWindow div is : ' + totalCount);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
So I have a HTML string that is similar to the following, and I'm trying to get a count of the .infoWindowParagraph tags in the FIRST .mapInfoWindow div. For whatever reason, it's not working as I expect and I'm not sure why.
HTML
<div class="mapInfoWindow">
<p class="infoWindowParagraph">DATA HERE</p>
<p class="infoWindowParagraph">DATA HERE</p>
<p class="infoWindowParagraph">DATA HERE</p>
<p class="infoWindowParagraph">DATA HERE</p>
</div>
<div class="mapInfoWindow">
<p class="infoWindowParagraph">DATA HERE</p>
<p class="infoWindowParagraph">DATA HERE</p>
<p class="infoWindowParagraph">DATA HERE</p>
<p class="infoWindowParagraph">DATA HERE</p>
</div>
<div class="mapInfoWindow">
<p class="infoWindowParagraph">DATA HERE</p>
<p class="infoWindowParagraph">DATA HERE</p>
<p class="infoWindowParagraph">DATA HERE</p>
<p class="infoWindowParagraph">DATA HERE</p>
</div>
jQuery/JavaScript
var testObj = $([string from above]);
console.log(testObj.find('.mapInfoWindow').find('.infoWindowParagraph').length);
-- returns 0 every time should return 4
-- also tried below trying to focus on first index (first instance of mapInfoWindow div in object returned)
var testObj = $([string from above]).get(0).find('.infoWindowParagraph').length);
-- still returns 0
update
Well damn, I got it working now. Sorry SO for the time-wasting here, overlooked the obvious!
$([string from above]), could you please post that selector and a little more of the surrounding html please?4from the first snippet, isn't that the expected behavior? Apologies, i'm not understanding.