Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6011 (reopened enhancement)

Opened 2 years ago

Last modified 3 months ago

getCssRule() stylesheet modification helper

Reported by: anonymous Assigned to: sam
Priority: low Milestone:
Component: Prototype Version:
Severity: minor Keywords:
Cc:

Description

I think you could use this function I made to get a css style rule element (Maybe it could be included in Prototype?) :

function getCssRule(selector) {
	var theRules = new Array();
	for (var i = 0; i < document.styleSheets.length; i++)
	{
		theRules = document.styleSheets[i].cssRules || document.styleSheets[i].rules;
		
		for (var j = 0; j < theRules.length; j++) {	
			if (theRules[j].selectorText == selector)
				return theRules[j];
		}
	}
}

With it you get the actual css rule element you ask by its selector and change it in real time. For example, you can change the following css

.variable_height_divs {
	height: 200px;
}

with these javascript code:

getCssRule('variable_height_divs').style.height = '300px';

I tested it in Firefox, IE 6 and Konqueror. It works OK.

I took the idea from http://www.twelvestone.com/forum_thread/view/31411.

Bye!

Change History

06/16/07 21:18:09 changed by josh

  • status changed from new to closed.
  • resolution set to invalid.

06/19/07 14:11:50 changed by jeremymcanally

  • status changed from closed to reopened.
  • resolution deleted.

Why is this invalid? He provided an enhancement; unless it's rejected by Core, I wouldn't close it.

04/03/08 01:06:29 changed by jdalton

+1 I totally dig!
I think some way to manage styleSheets is needed and
maybe something like this could be incorporated into it.

04/03/08 01:20:13 changed by jdalton

  • summary changed from Get css style element (I have an implementation) to getCssRule() stylesheet modification helper.

04/03/08 03:58:45 changed by kangax

Some tests perhaps?

04/03/08 13:19:43 changed by jdalton