473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Changing CSS styles with Javascript

Is it possible to change one of the CSS style attributes of say "ul
li"? Not a class or id, but a subset of HTML elements. If so, how
would this be done?

Jul 12 '07 #1
8 1673
On Jul 13, 12:17 am, matturn <matt...@gmail.comwrote:
Is it possible to change one of the CSS style attributes of say "ul
li"? Not a class or id, but a subset of HTML elements. If so, how
would this be done?
Actually changing their attributes? Only by looping over them.

Its faster and easier to have a prepared ruleset in your stylesheet
that targets ul.foo li (or similar) and then to change the className
of the ul element.

--
David Dorward
http://dorward.me.uk
http://blog.dorward.me.uk/

Jul 13 '07 #2
David Dorward wrote:
On Jul 13, 12:17 am, matturn <matt...@gmail.comwrote:
>Is it possible to change one of the CSS style attributes of say "ul
li"? Not a class or id, but a subset of HTML elements. If so, how
would this be done?

Actually changing their attributes? Only by looping over them.

Its faster and easier to have a prepared ruleset in your stylesheet
that targets ul.foo li (or similar) and then to change the className
of the ul element.
You can even dynamically insert CSS rules with better luck than
iterating every element.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jul 13 '07 #3
On Jul 13, 11:17 am, -Lost <maventheextrawo...@techie.comwrote:
David Dorward wrote:
On Jul 13, 12:17 am, matturn <matt...@gmail.comwrote:
Is it possible to change one of the CSS style attributes of say "ul
li"? Not a class or id, but a subset of HTML elements. If so, how
would this be done?
Actually changing their attributes? Only by looping over them.
Its faster and easier to have a prepared ruleset in your stylesheet
that targets ul.foo li (or similar) and then to change the className
of the ul element.

You can even dynamically insert CSS rules with better luck than
iterating every element.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
This is reply

Jul 13 '07 #4
On Jul 13, 7:17 am, -Lost <maventheextrawo...@techie.comwrote:
Its faster and easier to have a prepared ruleset in your stylesheet
that targets ul.foo li (or similar) and then to change the className
of the ul element.
You can even dynamically insert CSS rules with better luck than
iterating every element.
And you are responding with that to my suggestion why? Please aim your
quoting better.

Last time I looked at dynamically changing the stylesheet itself it
wasn't feasible as, between the major browsers, one had a proprietary
method for doing it, one or two supported the standard, and another
didn't provide any method to do it at all.

Has that changed?

--
David Dorward
http://dorward.me.uk
http://blog.dorward.me.uk/

Jul 13 '07 #5
On Jul 13, 6:13 am, David Dorward <dorw...@gmail.comwrote:
On Jul 13, 7:17 am, -Lost <maventheextrawo...@techie.comwrote:
Its faster and easier to have a prepared ruleset in your stylesheet
that targets ul.foo li (or similar) and then to change the className
of the ul element.
You can even dynamically insert CSS rules with better luck than
iterating every element.

And you are responding with that to my suggestion why? Please aim your
quoting better.

Last time I looked at dynamically changing the stylesheet itself it
wasn't feasible as, between the major browsers, one had a proprietary
method for doing it, one or two supported the standard, and another
didn't provide any method to do it at all.

Has that changed?

--
David Dorwardhttp://dorward.me.ukhttp://blog.dorward.me.uk/
Last I checked, it can be done across the latest versions of major
browsers, but it is messy. IE6 is the culprit. If you want any
semblance of backward compatibility with older browsers and hope to
have your app run on mobile devices, appliances, etc. you shouldn't do
it.

Jul 13 '07 #6
matturn wrote:
Is it possible to change one of the CSS style attributes of say "ul
li"? Not a class or id, but a subset of HTML elements. If so, how
would this be done?
Yes, here is code by Martin Honnen that shows how to add and modify CSS
rules:

<URL: http://www.thescripts.com/forum/post343885-2.html >
I posted this link a couple of days ago, it is always good to search the
archives before asking a specific question. They are an amazing resource.
--
Rob
"We shall not cease from exploration, and the end of all our
exploring will be to arrive where we started and know the
place for the first time." -- T. S. Eliot
Jul 13 '07 #7
On Jul 13, 12:51 pm, RobG <rg...@iinet.net.auwrote:
Yes, here is code by Martin Honnen that shows how to add and modify CSS
rules:

<URL:http://www.thescripts.com/forum/post343885-2.html>
Looks like it doesn't work (or at least, hasn't been tested) in Opera
or Safari/Konq.

--
David Dorward
http://dorward.me.uk
http://blog.dorward.me.uk/

Jul 13 '07 #8
On Jul 13, 2:51 pm, David Dorward <dorw...@gmail.comwrote:
Looks like it doesn't work (or at least, hasn't been tested) in Opera
or Safari/Konq.
Whoops. Opera is mentioned, but it uses an entirely different
technique that doesn't appear to allow existing rules to be modified.

Hmm, and the example uses invalid CSS.

--
David Dorward
http://dorward.me.uk
http://blog.dorward.me.uk/

Jul 13 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jeff Thies | last post by:
I have a number of elements of "some-class". I'd like to change the styles of some-class: from ..some-class{color: red; display: block} to
5
by: Andrew Poulos | last post by:
I'm trying to change a style in a stylesheet. The following code works in FF, MZ, and IE6 but IE 5 gives the error of "invalid procedure call or argument": var oStyleSheet =...
12
by: dan.vendel | last post by:
Hi, I know nothing about javascript, but quite a lot about regulat html and CSS. Have bumped into a problem that people in this fine congregation perhaps can help me with. I'm making a...
5
by: T. Wong | last post by:
I want to have a single CSS style sheet control the look of my whole asp.net application but I need to set the values in this CSS from code in the start page as the CSS values will be stored in a...
8
by: Bosconian | last post by:
I have two multiple select inputs. Initially the first contains a bunch of items and the second is empty. Using a common method, I move items back and forth by double clicking on them. This...
4
by: Sam Carleton | last post by:
How do I change the CSS colors via JavaScript DOM? Let me explain... I am working on a Windows application (in C#) that displays some HTML. In one place the HTML is a status window. What happens...
10
by: sbaker8688 | last post by:
My God, how on earth do you use javacript to change the text color of an input element, and have it work with IE??? I've tried numerous solutions. All of them work on browsers such as Mozilla. ...
5
by: Dinsdale | last post by:
Without using CSS styles or linked stylesheets, I need to apply formatting to text links that use rollover effects. I can NOT get the underline to show using this technique: <A...
4
by: splounx | last post by:
Hi there, I am a relative CSS & JavaScript novice and I have a particular problem that is beyond my level of knowledge so I thought I'd tap the collective wisdom of this group. I would like...
6
by: Rafaell | last post by:
Hi, everyone! I hope you guys can help me. I´m working on a website which deals with 4 different css styles. Once in the Homepage, the user can choose one link out of four to enter the site....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.