473,385 Members | 1,661 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,385 software developers and data experts.

Using javascript to change styles

Using javascript, how can I change an attribute for ALL anchors (A:hover) on the webpage?
Dec 30 '08 #1
6 1807
How can I change a style attribute for all anchors on a webpage?

Right now, i have a link pointing to a javascript function; i.e.

<a href="javascript: ChangeLinkCursor();">Click to change cursor when hovering over links</a>

What do i need to include in the ChangeLinkCursor function to change the style for ALL anchors (not just for one link but for ALL links on the webpage, i.e. I don't want to use getElementById 500 times if there are 500 links on the page)? Is there a simple way to change the style like below, or do I need to use getElementsByTag and use a for loop?

i.e. original style:
a:hover {cursor: default;}

new style:
a:hover {cursor: wait;}

Thanks!!
Dec 30 '08 #2
Dormilich
8,658 Expert Mod 8TB
try the advanced CSS interface
see Stylesheet object – MDC
Dec 30 '08 #3
I guess a better question, although a little broader, is the following: is there a way to change the style for a certain type of tag (using javascript)? i.e. How would i use javascript to change all divs from block elements to inline? Or change font size for all <P> from 16pt font to 12pt font? :confused:
Dec 30 '08 #4
Dormilich
8,658 Expert Mod 8TB
it's like you said, getElementsByTagName(). although you can try the stylesheet object stylesheet – MDC
Dec 30 '08 #5
Frinavale
9,735 Expert Mod 8TB
I'm not sure why you wouldn't just use the appropriate style to begin with but you can retrieve all elements of a particular type on a page in JavaScript using the document.getElementsByTagName method.

For example:

Expand|Select|Wrap|Line Numbers
  1.  var allInputElements=document.getElementsByTagName('input');
The above code retrieves all input elements on the page...you can loop through them and check if their type is the type you want to apply the JavaScript to:

Expand|Select|Wrap|Line Numbers
  1. for(var i = 0; i < allInputElements.length; i++)
  2. {
  3.     var temp = allInputElements[i];
  4.     if(temp.type=="......")
  5.     {
  6.       //Do something
  7.     }
  8. }
  9.  
Dec 30 '08 #6
gits
5,390 Expert Mod 4TB
threads merged - please don't double post your questions ...

kind regards,
MOD
Dec 30 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: codeslayer | last post by:
Greetings to everyone in ‘forum-land': I have a problem that has plaguing me to no end. It is a CSS-related question, and I have not seen this question posted anywhere in forums or through...
7
by: johkar | last post by:
I am confused on childNodes or children. When you have nested lists, I would think it would all be one list in the Dom, this doesn't seem to be the case. So how do you traverse an unordered list?...
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...
7
by: Sandy | last post by:
Hello - I have a form that when submitted checks the database and if the username is already taken, a label shows indicating same. I need to make that label NOT visible after the user clicks...
16
by: Giggle Girl | last post by:
Hi there, I have a nav tree similar to the XP Windows Explorer in behavior. It uses styles to underline a row on mouseover, and change the look of a row when clicked. Currently, it is working...
3
by: jnag | last post by:
Hello, I have a website with various font options (small to large) buttons that the user can click on the banner, which runs through the site. Site contains both static and dynamic content. I...
8
by: moondaddy | last post by:
I'm posting code for a user control ( FunctionConnectorSelector) below which has 3 content controls in it. each content control uses a style from a resource dictionary merged into the app.xaml...
4
Frinavale
by: Frinavale | last post by:
So a while ago I created a Tab Strip Control (before the AjaxToolkit had theirs otherwise I would have probably just used theirs). When I looked at the AjaxToolkit control to see how they got...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.