Jquery递归选择器

时间:2010-03-17 06:58:23

标签: jquery css-selectors truncate

我有很多<div class="productlistname"><a href="#">The Text!</a></div>。我想要做的就是遍历所有.productlistname并截断文本并用截断的版本替换当前文本。

这是我到目前为止所做的:

$(".productlistname a").html($(".productlistname a").html().substring(0,10));

这只是截断第一个,并用第一个截断的版本替换.productlistname的其余部分。

3 个答案:

答案 0 :(得分:1)

$(".productlistname a").each(function() {
  $(this).html($(this).html().substring(0,10));
});

答案 1 :(得分:1)

$(".productlistname a").each(function () {
    $(this).html($(this).html().substring(0,10));
});

答案 2 :(得分:0)

$(".productlistname a").each(functon(){
  // loopy loop
});