473,657 Members | 2,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1690
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 <maventheextraw o...@techie.com wrote:
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 <maventheextraw o...@techie.com wrote:
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 <maventheextraw o...@techie.com wrote:
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.ukht tp://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.ne t.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
10335
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
1545
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 = window.document.styleSheets.imports; oStyleSheet.addRule("td","font-size:1.2em;"); Is there a way to do this with IE 5? Andrew Poulos
12
2559
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 webshop. When user eventually ends up at the credit card processor's secure pages, the styles are quite different from the actual site's. I have managed to change some basics through a control
5
1448
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 data base. First, is this possible? Since CSS is plain text I could manipulate it all with string string functions in code, BUT, are there any classes or functions that make it easier to affect CSS parameters at run time?
8
3912
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 portion works perfectly, but I would also like to change the background color of the select element with the current focus. I have defined the following classes: ..selected {
4
1802
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 is the static HTML page is embedded into the application. The static page displayed and then the C# code gets a hold of the HTML DOM from the web browser and updates what pieces need to be updated. What I need to do now is change the colors...
10
4321
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. But none of them work on IE. This works in every browser I've tried besides IE: var whatever = document.createElement( 'input' ); whatever.type = 'text'; // (more code)...
5
1875
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 onmouseover="this.style.color='#000000'" style="FONT-SIZE: 12pt; COLOR: #000000; FONT-FAMILY: Arial, Helvetica; TEXT-DECORATION: underline;" onmouseout="this.style.color='#000000' TEXT-DECORATION: none;" href="#">Search</A>
4
2709
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 to know if there is a means of writing JavaScript that will dynamically display the styles which are currently applied to any DOM element on a web page ( i.e., those applied by ID, those applied by class, etc.) as the user moves their mouse over...
6
1432
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. Depending on the link he chooses, all the following pages will follow a different style. So, my question is: how can I make this decision taken in Home to be understood by all the other pages? The css style they´ll load depends on this previous choice.....
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8850
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.