Solved

CSS looks different after html injection

Posted on 2013-06-03
3
339 Views
Last Modified: 2013-06-04
Please have a look at http://jsfiddle.net/rgcBs/
A .js interval injects html divs equal to other divs already there. CSS rules apply the same to all divs, but the injected divs do not look the same as the divs already there.
Demo source:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
#divScroll div span
{
    display: inline-block;
    border: 1px solid black;
    margin: 0px;
    padding: 0px;
}

.col1 { width: 5%; }
.col2 { width: 25%; }
.col3 { width: 10%; }
.col4 { width: 30%; }

    </style>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script type="text/javascript">
        var hInterval;
        var iCount = 0;
        $(document).ready(function () {
            hInterval = setInterval(function () {
                html = '<div class="row"><span class="col1">'+iCount+'</span><span class="col2">asdfsadfasdfsdf</span><span class="col3">Test3</span><span class="col4">Teasdasdfasasdasdfst4</span></div>';
                $('#divScroll div.heading').after(html);
                iCount++;
                if (iCount == 10) clearInterval(hInterval);
            }, 1000);
        });
    </script>
</head>
<body>
    <div id="divScroll">
        <div class="heading">
            <span class="col1">Col1</span>
            <span class="col2">Column2</span>
            <span class="col3">Col3</span>
            <span class="col4">This is Col4</span>
        </div>
        <div class="row">
            <span class="col1">15</span>
            <span class="col2">Long long</span>
            <span class="col3">Sh</span>
            <span class="col4">Even longer</span>
        </div>
        <div class="row">
            <span class="col1">15</span>
            <span class="col2">Long long</span>
            <span class="col3">Sh</span>
            <span class="col4">Even longer</span>
        </div>
    </div>
</body>
</html>

Open in new window


Please, tell me how I can make it look like a table, and that the cells are the same width wether they are injected or there already.
0
Comment
Question by:lefodnes
3 Comments
 

Author Comment

by:lefodnes
ID: 39217619
I made it have the exact same HTML and content of elements : http://jsfiddle.net/rgcBs/1/
0
 
LVL 58

Accepted Solution

by:
Gary earned 250 total points
ID: 39217691
Add \n after each of your spans in the js
0
 
LVL 25

Assisted Solution

by:Kyle Hamilton
Kyle Hamilton earned 250 total points
ID: 39217778
you can do above if you want the spaces that those inline elements create between each other.

the other thing you can do is display:block; and float:left; This will remove the spaces between elements:

http://jsfiddle.net/rgcBs/5/
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn how to dynamically set the form action using jQuery.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now