DotDragnet
May 21, 2012, 06:39:30 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Mobile users - Our forum is Tapatalk enabled. http://www.tapatalk.com/
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Target css class with javascript  (Read 1986 times)
trx
Newbie
*
Posts: 37



View Profile WWW Awards
« on: January 08, 2008, 09:42:38 AM »

Hoping to get some assistance - Jeepstone sent me along here as I used to be his monkey until he departed for pastures new

<li id="menuitem_4_private" class="mainlevel_active_private"><a id="menulink_4_private" class="mainlevel_active_private" href="#">Portfolio</a>
<ul id="menulist_4_private" style="visibility: hidden; top: 87px;">
<li id="menuitem_4_1_private" class="sublevel_private">
<a id="menulink_4_1_private" class="sublevel_private" href="#">Testimonials</a></li>
<li id="menuitem_4_2_private" class="sublevel_current_private">
<a id="menulink_4_2_private" class="sublevel_current_private" href="#">Case Studies</a></li><li id="menuitem_4_3_private" class="sublevel_private"><a id="menulink_4_3_private" class="sublevel_private" href="#">Gallery</a></li>
</ul>
</li>

This is a section of my menu and I wish to target the <ul> below "mainlevel_active_private" depending on which menu item is active tried various things such as mootools etc. My menu is rendered in Joomla and makes use of "easymenu".

Richard
Logged
Rosco
Global Moderator
Hero Member
*****
Posts: 917



View Profile Awards
« Reply #1 on: January 08, 2008, 10:17:52 AM »

Hi Richard, and welcome to DDN smile

To target that ul in javascript you can grab it by its id, like this:

document.getElementbyId('menulist_4_private')

hope this helps
Logged
trx
Newbie
*
Posts: 37



View Profile WWW Awards
« Reply #2 on: January 08, 2008, 10:38:30 AM »

That does help but the active ul changes from page to page which I wish to target
Logged
Jeep Stone
Hero Member
*****
Posts: 908



View Profile WWW Awards
« Reply #3 on: January 08, 2008, 11:20:42 AM »

Rich,

If you're using Sam's easymenu, can you not modify the code to also add a class when you add the visibility?
Logged

Charisma Bypass
Hero Member
*****
Posts: 556



View Profile Awards
« Reply #4 on: January 08, 2008, 12:15:06 PM »

And make sure that if you are using EasyMenu, that you
pay for a license or provide a backlink (if it's a personal site).

Oh, and what JeepStone said - seems easiest.
Logged
trx
Newbie
*
Posts: 37



View Profile WWW Awards
« Reply #5 on: January 08, 2008, 02:51:41 PM »

I could do that but it has an inline style which would overide the css class but i guess i could drop the inline styles and do it using classes?
Logged
Charisma Bypass
Hero Member
*****
Posts: 556



View Profile Awards
« Reply #6 on: January 08, 2008, 03:23:46 PM »

You coudl maybe do something with jquery, based on the "style" attribute?  Have a hunt in Google.
Logged
trx
Newbie
*
Posts: 37



View Profile WWW Awards
« Reply #7 on: January 09, 2008, 02:34:56 PM »

In the end I went with the yahoo ui libary which seems pretty good for this type of thing it involves;

li = YAHOO.util.Dom.getElementsByClassName('mainlevel_current_private', 'li')[0];
ul =  YAHOO.util.Dom.getLastChild(li);
YAHOO.util.Dom.setStyle(ul, 'visibility', 'visible');

This has got me pretty close just doing a few tweeks now
Logged
Jeep Stone
Hero Member
*****
Posts: 908



View Profile WWW Awards
« Reply #8 on: January 09, 2008, 02:51:46 PM »

There's something like getElementsByClassName in most of the frameworks, just called something different.
Logged

trx
Newbie
*
Posts: 37



View Profile WWW Awards
« Reply #9 on: January 09, 2008, 03:37:52 PM »

There is also something similar in prototype libary its just that yahoo was the easiest to get up and running.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!