开发者

jquery remove nonbreakingspaces

开发者 https://www.devze.com 2023-02-15 16:46 出处:网络
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:

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

精彩评论

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