I am trying to get the number inside of a <span> I am using .each() to find all the spans but having problems getting the number inside of it. I would like to attach the number in the span to the image name, but no luck??
Code:
var _td = $("td.tri-img span");
$.each(_td, function(i, val){
$(val).html();
console.log(val);
var _img = $('.wrap-graph.relative img');
var _img_src = 'img/triangle' + val + '.png';
_img.attr('src', _img_src);
});
HTML:
<td class="tri-img"><img class="one"src="" alt="" ><span>11</span></td>
<td class="tri-img"><img class="two" src="" alt="" ><span>33</span></td>
<td class="tri-img"><img class="three" src="" alt="" ><span>44</span></td>
<td class="tri-img"><img class="four" src="" alt="" ><span>66</span></td>
Try this:
EDIT: If you want to clean the text of any non-digits, do this: