Add new 'li' dynamically adds indentation in IE

A

Anat

Hi,
i need to add another "li" element to a list.
The "li" should be with 0 indentation.
When I statically write it (HTML/CSS), with ul/li margin/padding 0 - it
looks great.
When I dynamically add it (Javascript) - in IE (and not FF) it's ALWAYS
indented, no matter what!!

This is my javascript code:
var newLiElement = document.createElement('li');
newLiElement.style.padding = '0px';
newLiElement.style.margin = '0px';

List.appendChild(newLiElement);

newLiElement.parentNode.style.padding = '0px'; //even tried to update
the "ul" father node
newLiElement.parentNode.style.margin = '0px';

Even though - the div in IE looks like this:

List Header
first li
second li

But in FF the div looks like this (and this is the right scenario):
List Header
first li
second li

I event tried to define a new class with padding and margin 0 and use
newLiElement.className = 'no-padding-maring-class-name';
but it's still indented in IE.

How do I fix the IE to make it work???

Thanks, Anat.
 
I

Ian Collins

Anat said:
Hi,
i need to add another "li" element to a list.
The "li" should be with 0 indentation.
When I statically write it (HTML/CSS), with ul/li margin/padding 0 - it
looks great.
When I dynamically add it (Javascript) - in IE (and not FF) it's ALWAYS
indented, no matter what!!

This is my javascript code:
var newLiElement = document.createElement('li');
newLiElement.style.padding = '0px';
newLiElement.style.margin = '0px';

List.appendChild(newLiElement);

newLiElement.parentNode.style.padding = '0px'; //even tried to update
the "ul" father node
newLiElement.parentNode.style.margin = '0px';

Even though - the div in IE looks like this:

List Header
first li
second li

But in FF the div looks like this (and this is the right scenario):
List Header
first li
second li

I event tried to define a new class with padding and margin 0 and use
newLiElement.className = 'no-padding-maring-class-name';
but it's still indented in IE.

How do I fix the IE to make it work???
I don't know, I've never seen the problem and I script a lot of lists.
But I always set the styles in css, not in the script. Try a css rule
with 0 margin and padding for the parent ul, that should work.
 
A

Anat

Thanks Ian, but my CSS already contains margin and padding 0.
That's the reason that my static HTML/CSS list looks OK, whereas when I
add a list-entry dynamically it is wrongfully indentated in IE.
Any ideas?
Anat.
 
A

ASM

Anat a écrit :
Thanks Ian, but my CSS already contains margin and padding 0.
That's the reason that my static HTML/CSS list looks OK, whereas when I
add a list-entry dynamically it is wrongfully indentated in IE.
Any ideas?
Anat.
I've tried with my IE Mac and it is ok :

<html>
<script type="text/javascript">
var lix = 0;
function newli() {
where = document.getElementById('ici');
var newput = document.createElement('LI');
newput.id = 'put_'+lix;
newput.innerHTML = 'li added number = '++(1+lix*1);
where.appendChild(newput);
lix++;
}
</script>
<style type="text/css" media="all">
#ici li { margin: 0; padding: 0; color:red;}
</style>
<ol id="ici">
<li>example
<li><a href="#" onclick="newli();return false;">add li</a>
</ol>
</form>
<html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top