Categories

Scripting Stylesheets

?View Code JAVASCRIPT
 
 
			$(function(){
 
				function selectStylesheetByTitle(title){
					for(var i=0; i< document.styleSheets.length; i++){
						var thisStylesheet = document.styleSheets[i];
						var thisTitle = document.styleSheets[i].title;
						if(thisTitle.toLowerCase() == title.toLowerCase()){
							alert('found it: '+ i);
							return document.styleSheets[i];
						}
					}
				}
 
				//selectStylesheetByTitle('main');
 
 
/*
				function selectRuleBySelector(sel){
					var stylesheet;
					if(document.styleSheets[1].cssRules){
						theRules = document.styleSheets[1].cssRules;
					}else if(document.styleSheets[1].rules){
						theRules = document.styleSheets[1].rules
					}
					for(){
 
					}
				}
*/
 
 
 
 
				var theRules = new Array();
				console.log(document.styleSheets);
 
				setTimeout(function(){
					console.log(document.styleSheets[0].rules[0].cssText);
					try{
						            document.styleSheets[0].rules[0].style.color = 'green';
						console.log(document.styleSheets[0].rules[0].cssText);
					}catch(e){
						alert('oop!: '+ e.message);
					}
				}, 2000);
 
				if (document.styleSheets[1].cssRules){
					// Safari
					theRules = document.styleSheets[1].cssRules;
					console.log(theRules);
					for(var i=0; i<theRules.length; i++){
						var sel = theRules[i].selectorText;
						// console.log(sel);
						if(sel.toLowerCase() == 'button'){
							console.log(theRules[i].style);
							alert('button');
						}
					}
				} else if (document.styleSheets[1].rules){
					theRules = document.styleSheets[1].rules
					alert(2);
				}
 
			});

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

IMPORTANT! To be able to proceed, you need to solve the following simple math (so I know that you are a human) :-)

What is 12 + 3 ?
Please leave these two fields as-is: