Results 1 to 2 of 2

Thread: change div class on click

  1. #1
    Join Date
    Feb 2010

    change div class on click


    I have a tree menu on my site.

    The problem is the when I click on one of the closed menu points, the opened one doesnt close.

    if (firstChild.className.search(/open/) >= 0){
    	 	tg.className = tg.className.replace('open', 'closed');
    		firstChild.className = firstChild.className.replace('open', 'closed');
    	} else {
    	 	tg.className = tg.className.replace('closed', 'open');
    		firstChild.className = firstChild.className.replace('closed', 'open');
    The first child is the menu point that should open or close.

    Since I actualy have only two points that open as a tree menu, I would need to change the div class of the one that is already opened.

    Any thoughts are appreciated.

  2. #2
    Join Date
    Oct 2006
    I'd be careful to use "open" or "close" anywhere in code.
    Reserved words, you need to scramble them to similar "open1" "close1"

    Also, something I have seen never looked into it, cant think exactly the method-
    stoppropogation, or stopbubble... something

    I think that may be what you need here

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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