StabDev StabDev - 6 months ago 24
jQuery Question

find() not working properly. Cant find span

Trying to fill a span by finding it and using innterHTML but for some reason it doesn't do anything. No error, no succes, doesnt print anything. What has gone wrong?

<label class="myClass" data-id="1"><input type="checkbox" name="group" value="my_value">my value<span class="left" ></span></label>andmoreandmore


The classes are being looped through and the result is put in in every classes span

var element = $('.myClass')[i];
var numberThing = 50 - count;
$(element).find("span").innerHTML = numberThing + ' plekken vrij';

Answer

Well what has gone wrong is that you did not select the correct span, or better said.. none at all

You need to select span[0] because you are selecting a DOM element the wrong way.

var element = $('.myClass')[i];
var numberThing = 50 - count;
$(element).find("span")[0].innerHTML = numberThing + ' plekken vrij';