Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8274951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:54:10+00:00 2026-06-08T07:54:10+00:00

I am rendering a HTML table through Django. In this table, some of the

  • 0

I am rendering a HTML table through Django. In this table, some of the cells or columns contain “0”‘s as produced by my python code.

Is there any way in HTML to override that cell or column and for it to show instead a blank in the table cell rather than a 0?

I am using jQuery as well, if that helps.

<tr><td> Value</td>

{% for num in list %}
    <td> <b>{{num}}</b>
{% endfor %}</td>
</tr>

Output is a list which contains 3 zero’s…out of which I want two blanked out.

Lets say if I have something being returned that is

0
10
0
20 
0

But want

""
10
""
20
0


    $(".dem").each(function() {
        for ( var i = 0; i<2; i++)
        {
            if ($(this).html() == "0") {
            $(this).html(" ");         
            }
            i = i+1
        }
    });

I did that ^….however it turned all 3 zeros blank…why?
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:54:12+00:00Added an answer on June 8, 2026 at 7:54 am

    See the last edit for my final answer. I’m leaving the rest in to show how important it is to ask a good question, and to show what was tried, what the input looked like and what the expected output should have been. That would have saved a lot of time.


    Using jQuery, you can iterate over each table cell, check the value and change what it outputs. I prefer this over changing the actual data. It’s better to leave your data intact and only change the way it is displayed here.

    $("#test td").each(function() {
        if ($(this).html() == "0") {
            $(this).html("");
        }
    });
    

    You can see it in action here.

    Update:

    If only some <td>s should be changed, I recommend using a class for those.

    $(".noZeroAllowed").each(function() {
        if ($(this).html() == "0") {
            $(this).html("");
        }
    });
    

    It works with HTML like this:

    <table id="test">
        <tr>
            <td class="noZeroAllowed">10</td>
            <td class="noZeroAllowed">5</td>
            <td>0</td>
            <td>1</td>
        </tr>
        <tr>
            <td class="noZeroAllowed">11</td>
            <td class="noZeroAllowed">0</td>
            <td>9</td>
            <td>7</td>
        </tr>
    </table>
    

    Also see the updated fiddle.

    Update 2:

    If the data is not atomic and the cells have multiple values in them, like this:

    <table id="test">
        <tr>
            <td class="noZeroAllowed">10 0 foobar 0</td>
            <td class="noZeroAllowed">5</td>
            <td>0, 0, 0</td>
            <td>1</td>
        </tr>
    </table>
    

    Then you need to change the Javascript to use a regular expression instead. The \b means a word boundary. It will not work with decimals like 0.5 though.

    $(".noZeroAllowed").each(function() {
        var newStr = $(this).html().replace(/\b0\b/g, "");
        $(this).html(newStr);
    });
    

    See the updated fiddle.

    Update 3:

    This will turn all the zeros inside of <b> tags in the relevant class <td>s into empty strings, but leave the last zero intact.

    $(".noZeroAllowed").each(function() {
        var zeros = new Array;
        var b = $(this).find("b");
        for (var i = 0; i < b.length; i++) {
            $(b[i])
            if ($(b[i]).html() == "0") {
                zeros.push(b[i]);
            }
        }
        for (var i = 0; i < zeros.length - 1; i++) {
            $(zeros[i]).html("");
        }
    });
    

    See it here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any relation between doctype of an HTML document and browser rendering speed?
I have a HTML table with a column per row with this html code
This HTML table is being misinterpreted by some browsers, and I cannot understand why
I'm trying to layout an HTML table (it's tabular data) and it is rendering
I had the following HTML page rendering to use the Google Maps API. This
I am trying to use django-tables to create a sortable table out of some
Layout and rendering of HTML content can take some time if the HTML is
I need some advice on how to set column widths in a HTML table.
I am inserting data into a table which contains some basic html tags, double
I am rendering HTML locally in an iPad app using jQuery Mobile. The titles

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.