user3509693
user3509693

Reputation: 9

Remove blankspace from td class with greasemonkey

If I have webpage with for example alot of <td class="house">111 22</td>. The numbers are random but classname is the same and the blankspace between the numbers are at same position in all of them, and I want to remove the space in all of them after page is loaded. How should the script look like to work?

Upvotes: 0

Views: 200

Answers (3)

Naveen Chandra Tiwari
Naveen Chandra Tiwari

Reputation: 5123

    use the following code:

   <script type="text/javascript">

    window.onload = removeSpace;

    function removeSpace() {
        var emt = document.getElementById("mytable");//mytable is the Id of the table
        d = emt.getElementsByTagName("tr")[0],
         r = d.getElementsByTagName("td");
        for (var i = 0; i < r.length; i++) {
            var str = r[i].innerText;
            r[i].innerText = str.replace(" ", "");
        }
    }

</script>

Upvotes: 0

Amit Joki
Amit Joki

Reputation: 59232

Do this:

var elems = document.querySelectorAll('td.house');
for(var i = 0 ; i < elems.length; i++){
    elems[i].textContent = elems[i].textContent.replace(" ","");
}

Upvotes: 0

Cheong BC
Cheong BC

Reputation: 316

How about using this

var str = "111 22";    
    str = str.replace(" ","");

code example :

<script type="text/javascript">
 //Page Initial
 $(function() {
     removeSpace();
 });
 function removeSpace(){
   var str = $(".house").html();
       str = str.replace(" ","");
       $(".house").html(str);
 }

</script>

Upvotes: 0

Related Questions