0

I'm using Knack Online Database to create apps. I'm trying to find a way to hide empty space in a cell.

I have a table that has a text formula. The text formula combines multiple fields (question and answers) and separates them using <br>. This is how i have it set up:

<b>question1</b> answer1
<br>
<b>question2</b> answer2
<br>
<b>question3</b> answer3
<br>

For some records, some of the fields are empty so this is how it results:

<b>question1</b> answer1
<br>
<b></b>
<br>
<b>question2</b> answer2
<br>

In my table, the empty space would show and it would take so much space: Table

I've tried using this code but it didn't work:

$(document).on('knack-view-render.view_2665', function(event, view, data) {
  removeWhiteSpaces('kn-input-field_3288');
});

I'm not sure what's the best solution to hide the empty space. Is there a code that I could use to hide the <b></b><br> if the <b></b> was empty for this column/field?

2
  • What is removeWhiteSpaces function doing? Also, could you provide bigger chunk of HTML? Namely, pieces related to kn-input-field_3288 and knack-view-render.view_2665? Jul 17, 2019 at 18:11
  • html-tuts.com/…
    – A. Meshu
    Jul 17, 2019 at 18:22

4 Answers 4

3

Perhaps something like this in your CSS?

b:empty + br:empty,
b:empty {
  display: none;
}

This would hide every empty <b> tag and any empty <br> placed after an empty <b>.

Here's a fiddle.

0
0

Could you try something like this?

var empties = jQuery("b:empty");
var nextsBr = empties.next().filter('br');
nextBr.remove();
empties.remove();
0

You can use :empty and siblings selectors

$('b:empty').remove()

$('br + br').remove()
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<b>question1</b> answer1
<br>
<b></b>
<br>
<b>question2</b> answer2
<br>

0
0
$('b').each(function() {
    if ( $.trim( $(this).text() ).length == 0 ) {
        if ( $(this).children().length == 0 ) {
            $(this).text('');
            $(this).remove(); // remove empty paragraphs
        }
    }
});

Taken from here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.