jQuery showing HTML in somewhat different manner than the code with HTML only

I have this JSFiddle which shows the HTML as expected :


However, when I tried to use jQuery to display the same HTML as shown in the JSFiddle here, it started displaying the output in the following manner with so much space.

What am I doing wrong in the jQuery part? Thanks

Hi @Jack_Tauson_Sr, you can see the problem if you inspect the table with the dev tools:


So you’re appending everything directly to the table, rather than tds to trs etc. Now you can traverse the created elements like so:

  .append('<tr height="30">')
    .append('<td width="33%" align="left"><u><b>Summary, Testing, etc.. </b></u><br></td>') 
  .append('<tr height="5px"></tr>')
    // ...

… but for the sake of readability I’d rather create the table tree from a single HTML string, if this is an option.

Hi @m3g4p0p, Thanks for your answer. That makes sense.

I think this is what you were referring to.Yes, I can have everything in a single string like this:

  .append('<tr height="30"><td width="33%" align="left"><u><b>Summary, Testing, etc.. </b></u><br></td></tr><tr height="5px"></tr><tr><td title="Counts of total cars - Decending Order  " width="33%" style="padding-left:40px;"><ul style="list-style-type:  disc"><li>Counts of total cars - Decending Order  </li><ul></td><td width="33%" align="left"><img src="images/DownloadImage.jfif" title="Download" alt="Download" width="20" height="20"></td></tr>')

Because, ultimately, I am planning to populate few things (like Summary, Testing, etc.. , title="Counts of total cars - Decending Order ) dynamically by looping a json response so that I can have multiple tables one above another just like we discussed here. Thanks again for answering ! :slight_smile: Is this JSON response good to generate? - #9 by m3g4p0p

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.