开发者

jquery remove nonbreakingspaces

Well, i have a table that is generated dynamically and i don't have access to the source code. Each <tr> has a single <td> and inside a <td> i have:

<td><label>sdsd</label><input text /><label>uuyti</label><select><开发者_如何学Go;/select></td>

it happens that i am using css, and i want the fields on the two rows to be perfectly aligned, but on the second row, i have a nbsp between the second label and the select, so i want to remove that nbsp but i don't know how to reach it with jquery.

Thank you


If you want to remove all &nbsp; you can use the following:

$("tr td").html(function(i, h) {
    return h.replace(/&nbsp;/gi, "");
});

Example on jsfiddle.

If you want to place a &nbsp; after the second label you can use eq() and after()

$("tr td label:eq(1)").after("&nbsp;");

Example on jsfiddle.


   $("tr td").each(function(index, html){
        $(this).replaceWith($(this).html()+"&nbsp;");
     });

this appears to be working on jsfiddle. still testing

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜