0

I have a simple table, using bootstrap css. The table has the following classes

<table id="data-table" style="word-wrap: break-word" class="table table-condensed table-striped">

This works fine, when i add rows directly through the html file, but when i try to use javascript to append a new row, the striped css does not work as intended.

var table = $('#data-table');
table.children('tbody').append("<tr><td>User3</td><td>Real name 3</td><td>undefined</td><tr>");

JSFiddle example: https://jsfiddle.net/mtropkdx/

Is there any css refresh that needs to be executed to get the css working?

Edit: When i insepct the DOM i can se that there are empty between the inserted rows, i guess thats why i cant see the striped ones. But why are they there?

1 Answer 1

1

Your ending <tr> tag is another open tag. The normalized HTML is creating an empty row (use your dev console to inspect the fiddle's output window). This:

table.children('tbody').append("<tr><td>User3</td><td>Real name 3</td><td>undefined</td></tr>")

works just fine.

Updated fiddle: https://jsfiddle.net/mtropkdx/1/

Sign up to request clarification or add additional context in comments.

1 Comment

percect, thanks. Hard to stop those errors sometimes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.