May 21, 2012, 06:39:30 PM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
: Mobile users - Our forum is Tapatalk enabled.
http://www.tapatalk.com/
Home
Help
Search
Login
Register
DotDragnet
>
The Tech Side
>
Tech stuff
>
Target css class with javascript
Pages: [
1
]
Go Down
« previous
next »
Print
Author
Topic: Target css class with javascript (Read 1986 times)
trx
Newbie
Posts: 37
Target css class with javascript
«
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
Re: Target css class with javascript
«
Reply #1 on:
January 08, 2008, 10:17:52 AM »
Hi Richard, and welcome to DDN
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
Re: Target css class with javascript
«
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
Re: Target css class with javascript
«
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
Jeepstone
Charisma Bypass
Hero Member
Posts: 556
Re: Target css class with javascript
«
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
Re: Target css class with javascript
«
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
Re: Target css class with javascript
«
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
Re: Target css class with javascript
«
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
Re: Target css class with javascript
«
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
Jeepstone
trx
Newbie
Posts: 37
Re: Target css class with javascript
«
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
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General Category
-----------------------------
=> General Discussion
=> Jee's Forum of Appalling Jokes
-----------------------------
The Creative Side
-----------------------------
=> Arty stuff
=> Photography
=> On the web
-----------------------------
The Tech Side
-----------------------------
=> Tech stuff
=> Hardware & Software
-----------------------------
The Business Side
-----------------------------
=> Anything business related
-----------------------------
The Practical Side
-----------------------------
=> Practical Advice
DotDragnet
>
The Tech Side
>
Tech stuff
>
Target css class with javascript
Loading...