Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Getting js to apply css important to a value
Old 11-14-2009, 01:45 PM Getting js to apply css important to a value
Skilled Talker

Posts: 81
Trades: 0
Dear friends

I have a script that puts a different css color and background image onto a menu for the link that has been clicked to open an iframe. This works fine, but because elements of the menu have to already have fixed css !important specifications, the javascript css modification is not 'as strong' as that.

The relevant part of the script is

Code:
for(var i = 0; i < as.length; i++) { 
as[i].style.color = 'white'; //default text color 
as[i].style.background = '#2175BC'; //default backgroundcolor 
if(as[i].href.toLowerCase() == pagename.toLowerCase()) { 
as[i].style.background = 'url(http://www.internetevangelismday.com/images/arrowlargeyellow.gif) no-repeat left blue';    //desired highlight bg colour second level menu


}
The value I would like to apply !important strength to is the background image item. Adding !important to the line itself does not work. It might carry a bit more strength too if the background color blue was separated from the background image. Can you see any way to do this?

Best wishes and thanks

Tony
__________________

Please login or register to view this content. Registration is FREE
soon is offline
Reply With Quote
View Public Profile Visit soon's homepage!
 
 
Register now for full access!
Old 11-19-2009, 10:40 AM Re: Getting js to apply css important to a value
Super Talker

Posts: 139
Name: John Davis
Trades: 0
The !important notation is used to rewrite users css defenition only.
So, your problem is not with !importan. Please, provide other relating code.
__________________
»
Please login or register to view this content. Registration is FREE
- Interactive maps for websites
»
Please login or register to view this content. Registration is FREE
for web developers
MapMaster is offline
Reply With Quote
View Public Profile Visit MapMaster's homepage!
 
Old 11-24-2009, 08:33 AM Re: Getting js to apply css important to a value
Skilled Talker

Posts: 81
Trades: 0
Thanks so much. Here's the full script:

Code:
function parNode(elm, elmType) {
                 if(elm.parentNode.nodeName.toLowerCase() == 'div') {
                     return false;
                }
                 var par = elm.parentNode.nodeName.toLowerCase() == elmType.toLowerCase() ?
   
                  elm.parentNode : parNode(elm.parentNode, elmType);
                 return par;
            }

function highlight_menu(pagename, h) { 
document.getElementById('bookreviews').style.height = h + 'em'; 
var menu = document.getElementById('channel'); 
var as = byTag('a', menu); 
for(var i = 0; i < as.length; i++) { 
as[i].parentNode.style.background = 'url() no-repeat left #2175BC'; //default bgcolour 
if(as[i].href.toLowerCase() == pagename.toLowerCase()) { 
as[i].parentNode.style.background = 'url(images/arrowlargeyellow.gif) no-repeat left #0000FF'; //desired highlight bg colour 
if(parNode(as[i].parentNode, 'li')) { 
parNode(as[i].parentNode, 'li').style.background = 'url(images/arrowlargeyellow.gif) no-repeat left #0000FF'; // firstlevel bgcolor 
} 
} 
} 
}

function byTag(tag, parent) {
        if(parent) {
            if(parent.length && parent.length > 1) {
                //parent is an array of elements
                var arr = new Array();
                for(var i = 0; i < parent.length; i++) {
                    var ithpar = parent[i].getElementsByTagName(tag);
                    for(var j = 0; j < ithpar.length; j++) {
                        arr.push(ithpar[j]);
                    }
                }
                return arr;
            } else {
                //parent is a single element
                return parent.getElementsByTagName(tag);
            }
        } else {
            return document.getElementsByTagName(tag);
        }
    }
It is particularly the background image specs that I would like to have the power of css !important.

Thanks for any ideas

Best wishes

Tony
__________________

Please login or register to view this content. Registration is FREE
soon is offline
Reply With Quote
View Public Profile Visit soon's homepage!
 
Old 11-24-2009, 09:04 AM Re: Getting js to apply css important to a value
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You will find it somewhat difficult due to browser "issues"

http://www.quirksmode.org/dom/w3c_css.html#properties
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-24-2009, 11:21 AM Re: Getting js to apply css important to a value
Skilled Talker

Posts: 81
Trades: 0
Ah well. Thanks!


Best wishes


Tony
__________________

Please login or register to view this content. Registration is FREE
soon is offline
Reply With Quote
View Public Profile Visit soon's homepage!
 
Reply     « Reply to Getting js to apply css important to a value
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.47163 seconds with 12 queries