SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding padding to list items

    Hi All,

    I have a dynamically generated list of <li>s and I need to add an increasing amount of padding to each one to accommodate a curved background image.

    I've put together the following:

    Code:
    function alignList() {
    	var p = 0;
    	var items = document.getElementById("articles").getElementsByTagName("li");
    	for (var i=0; i<items.length; i++) {
    		items[i].style.paddingLeft = "p+5";
    	}
    }
    "articles" is the id of the containing <ul>

    Unfortunately, the above doesn't do anything. Can anyone help?

    Thanks

    Robin

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,423
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Assuming this isn't a CSS cascading issue:

    Code:
    function alignList() {
    	var p = 0;
    	var items = document.getElementById("articles").getElementsByTagName("li");
    	for (var i=0; i<items.length; i++) {
    		items[i].style.paddingLeft = (p+5)+"px";
    	}
    }
    First do the math to add p and 5 and then add the px to the end of it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •