Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 3rd, 2005, 12:35 PM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default TREE USING UL/LI

Hi,

I am trying to create a tree using the ul tag. When I click on the LI item the node expands and I show the contents of a DIV. However, when I click on the DIV contents the tree contracts.

I do not want it to happen. I want the tree to contract only when I click on the LI item(text).

I tried to open the LI tag and closing it before the opening DIV tag but it did not work.

I would appreciate if someone could help me to solve this problem.

Cheers,

Pallone

<UL>
    <li onclick="doExpand(this, desc1)" id="li1" class="itemContracted">Washington
        <DIV class="descExpanded" id="desc1">
            Captial: Olympia<br> Population: 4.8 Million (c. 1990) <br>Area: 68,000 sq miles
        </DIV>
    </li>
</UL>

Reply With Quote
  #2 (permalink)  
Old February 3rd, 2005, 04:08 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

In IE you can put
Code:
onclick="event.cancelBubble = true;"
in the div.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old February 7th, 2005, 08:10 AM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Hi Joe,

Thanks for your help. This has stopped the div to contract as expected. Would you know how to do that in Netscape?? Thanks

Does anyone know how to position the <li> tag of a nested[list] tag? I am trying
to nest lots of <li> like this:[list]<li>[list]<li></li></ul></li></ul> .

But as I keep adding more[list] and <li> the text (nodes) keeps moving too far to the right. I would like to control the amount of indent that each[list] <li> applies. Is it possible??

Cheers,

Claudio

Reply With Quote
  #4 (permalink)  
Old February 10th, 2005, 05:57 AM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Hi,

Maybe my second question was not clear and I would like to try again.

How can use javascript to remove unwnated margin from a[list]<li> tags??

cheers,

Claudio

Reply With Quote
  #5 (permalink)  
Old February 11th, 2005, 04:15 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Claudio,

More of a css thing - set the margin-left & padding-left properties of the[list] to a width in pixels (padding for mozilla etc, margin for IE).

HTH,

Chris

Reply With Quote
  #6 (permalink)  
Old February 11th, 2005, 10:35 AM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Hi Chris,

Thanks. I will try that.

Claudio



Reply With Quote
  #7 (permalink)  
Old February 14th, 2005, 08:17 AM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Hi Chris,

I tried to use padding and margin as you suggested but I still cannot control the position of the <li> tag. When I use padding-left : 20px;
margin-left: 20px for the <UL> tag I think the <LI> tag is also using the same values and I get the unwanted margin.

Example

UL{
padding-left : 20px;
margin-left: 20px;
}


Washington <LI>
     This is a text <LI>
           Second level <LI>

As you can see the text goes to far to the right. Are you sure it is not possible to control the margin with javascritp??

Cheers,

Claudio








Reply With Quote
  #8 (permalink)  
Old February 15th, 2005, 05:42 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Claudio,

Can you paste the source html for your output and describe exactly how you want it to look, please?

Thanks,

Chris

Reply With Quote
  #9 (permalink)  
Old February 15th, 2005, 07:19 PM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Hi Chris,

This is the html I am using. As you can see I have a top <UL> tag and then a <LI> tag. The text for the top <LI> tag is "Washington".

Then, I use a DIV tag to hide the second level which has another <UL> and <LI>.

AS I have said on my previous post, I would like to be able to control the margin of the <LI> tags no matter what level there are in. So instead of having this:

Washington <LI>
         This is a text <LI>
                 Third level <LI>

I would like to have this:

Washington <LI>
 This is a text <LI>
  Second level <LI>

Cheers,

Claudio




<body>
<UL>
    <li onclick="doExpand(this, desc1, 2)" id="li1" class="itemContracted">Washington
        <DIV onclick="event.cancelBubble = true;" class="descExpanded" id="desc1">
            [list]
                <li onclick="doExpand(this, desc21, 3);" class="itemContracted" >
                    This is a text
                    <div onclick="event.cancelBubble = true; doRedirect(this);" id="desc21" class="descExpanded">Third level</div>
                </li>
            </ul>
        </DIV>
    </li>


    <li onclick="doExpand(this, desc2, 0)" class="itemContracted">Oregon
        <DIV class="descExpanded" id="desc2" onclick="event.cancelBubble = true; doRedirect(this);">
            Captial: Salem<br> Population: 2.8 Million (c. 1990) <br>Area: 97,000 sq miles
        </DIV>
    </li>
    <li onclick="doExpand(this, desc3, 0)" class="itemContracted">Idaho
        <DIV class="descExpanded" id="desc3">
            Captial: Boise<br> Population: 1.0 Million (c. 1990) <br>Area: 83,000 sq miles
        </DIV>
    </li>
</UL>
</body>



Reply With Quote
  #10 (permalink)  
Old February 16th, 2005, 04:54 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Claudio,

Try changing the css to this...
Code:
ul{
    padding-left: 3px;
    margin-left: 3px;
    list-style: none;
}
HTH,

Chris

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Centering an UL element within DIV keithc BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 2 April 4th, 2013 04:13 PM
<li></li> issue Adam H-W CSS Cascading Style Sheets 1 November 5th, 2007 06:41 AM
create <ul> with alternating class on <li> element Brian Campbell XSLT 2 November 3rd, 2006 06:07 PM
Something about li and ul sfs00784 CSS Cascading Style Sheets 1 July 31st, 2005 02:03 AM
Bullets formatting with UL tag apd8x HTML Code Clinic 1 July 30th, 2003 05:27 PM



All times are GMT -4. The time now is 09:07 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.