Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Javascript unable to find certain style sheet rules

Reply
Thread Tools

Javascript unable to find certain style sheet rules

 
 
Jake Barnes
Guest
Posts: n/a
 
      04-13-2009
I have a style sheet with this rule in it:

li#patterns em, li#apparel em, li#tapes em, li#appliques em,
li#closures em, li#mend em, li#decor em, li#sewing em, li#quilting em,
li#ribbon em, li#crochet em, li#kits em, li#products em{
background: url(Simplicity Home/bg-nav.png) no-repeat;
cursor: pointer;
}


I want to get the background image for this, and for all other rules
that have background images.


I have the following code to loop through all the rules of all the
style sheets:

var styleSheets = document.styleSheets;
var stringOfAllStyleRules = "";
for (var i=0; i < styleSheets.length; i++) {
var thisStyleSheet = styleSheets[i];
if (thisStyleSheet.cssRules) {
var listOfStyleSheetRules = thisStyleSheet.cssRules;
}
if (thisStyleSheet.rules) {
var listOfStyleSheetRules = thisStyleSheet.rules;
}

if (typeof listOfStyleSheetRules == "undefined") {
window.status = "No style rules could be found";
} else {
for (var r=0; r < listOfStyleSheetRules.length; r++) {
var thisRule = listOfStyleSheetRules[r];
if (typeof thisRule["style"] != "undefined") {
var styleObject = thisRule["style"];
var cssText = thisRule["cssText"];
var backgroundImageUrl = styleObject["backgroundImage"];
// if (backgroundImageUrl != "") {
stringOfAllStyleRules += backgroundImageUrl;
stringOfAllStyleRules += "<br /> \n";
stringOfAllStyleRules += cssText;
stringOfAllStyleRules += "<br /><br /> \n";
// }
}
}
}
}
if (stringOfAllStyleRules) document.getElementById("recently-viewed-
items").innerHTML = stringOfAllStyleRules;

The last line is simply so I can see the output on screen. This is how
the code renders the above rule:

li#patterns em, li#apparel em, li#tapes em, li#appliques em,
li#closures em, li#mend em, li#decor em, li#sewing em, li#quilting em,
li#ribbon em, li#crochet em, li#kits em, li#products em { cursor:
pointer; }

The cursor is still there, but the background is gone. Why?

I'm testing this code on FireFox 3.0.5

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      04-13-2009
On Apr 13, 2:09*pm, Jake Barnes <lkrub...@geocities.com> wrote:
> I have a style sheet with this rule in it:
>
> li#patterns em, li#apparel em, li#tapes em, li#appliques em,
> li#closures em, li#mend em, li#decor em, li#sewing em, li#quilting em,
> li#ribbon em, li#crochet em, li#kits em, li#products em{
> * * * * background: url(Simplicity Home/bg-nav.png) no-repeat;


Put the URL in quotes.

--
Rob
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to cache style sheet helveticus ASP .Net 3 07-07-2008 06:12 PM
Content Page specific style style sheet rshillington@gmail.com ASP .Net 0 07-14-2006 03:45 PM
rules for Cisco PIX 525 firewall rules KAS Cisco 2 10-02-2005 07:12 PM
Sharing style sheet and javascript file Aaron Prohaska ASP .Net 1 01-17-2005 10:43 PM
how do I get all the div's that have a certain style sheet class lkrubner@geocities.com Javascript 9 12-30-2004 02:05 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57