Milano Slesarik Milano Slesarik - 1 month ago 7
HTML Question

Uncaught TypeError: lab.find is not a function

I can't figure out why

says that lab.find() is not a function. I'm looking for a text in this html:

<div class="btn-group col-md-4" data-toggle="buttons">

<label data-pk="4" id="languagebuttonselect1" class="btn prmr-btn-empty top-margin left-margin center-elements target_language_choice active" style="padding: 8px; color: black; width: 100%;">
<input type="checkbox" name="target_languages" value="4" autocomplete="off">

<img align="left" width="30px" style="margin-bottom: 0;" src="/static/img/flags/550px\gb.png">
<b class="left-margin" style="text-align: left">English</b>

And I want to get text (in this case "English") when a class of the tag (label) is

function refreshSummaryTaretLanguages(){
var actives = $('');
var summ_ul_targ_langs = $('#summary_target_languages > ul');

$.each(actives,function (_,lab) {

Unfortunately it can't find anything in such tag and I don't know what to do.


jQuery passes the $.each callback the elements of the array, so you're getting DOM nodes, not jQuery objects.

It would be simpler to just use the .each() method on the jQuery object you already have:

$(actives).each(function() {

The .each() callback does basically the same thing as $.each(), and will also pass in the element. It also arranges for the callback to be invoked such that this references the element too. Wrapping this as $(this) gives you a jQuery object from which you can call .find().