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

Manipulate all tags

Ho can I create a function in javascript to dynamically toggle all <em>
tags between bold and italic?
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #1
3 4630
Fabian hu kiteb:
Ho can I create a function in javascript to dynamically toggle all
<em> tags between bold and italic?


Specifically, without adding name or id attributes to these tags, is it
possible to find all <em> (or whatever) tags?
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #2
Fabian wrote on 07 nov 2003 in comp.lang.javascript:
Fabian hu kiteb:
Ho can I create a function in javascript to dynamically toggle all
<em> tags between bold and italic?


Specifically, without adding name or id attributes to these tags, is it
possible to find all <em> (or whatever) tags?


In IE:

var coll = document.all.tags("DIV");
if (coll!=null) {
for (i=0; i<coll.length; i++) {
coll[i].style.fontSize = "7pt"
coll[i].style.color = "black"
}
}

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #3
"Fabian" <la****@hotmail.com> writes:
Fabian hu kiteb:
Ho can I create a function in javascript to dynamically toggle all
<em> tags between bold and italic?


Specifically, without adding name or id attributes to these tags, is it
possible to find all <em> (or whatever) tags?


Yes. In standard compliant browsers, and IE from version 5, you can use

Setting all ems italic:
var ems = document.getElementsByTagName("em");
for (var i=0;i<ems.length;i++) {
ems[i].style.fontStyle = "italic";
ems[i].style.fontWeight = "bold";
}

It is probably simpler to just create some CSS classes:
<style type="text/css">
em.bold {
font-weight:bold;
font-style:normal;
}
em.italic {
font-weight:normal;
font-style:italic;
}
</style>

You can then change all ems to one or the other:

var ems = document.getElementsByTagName("em");
for (var i=0;i<ems.length;i++) {
ems[i].className = "italic"; // or "bold"
}

If you care about IE 4, you can use
var ems = document.all.tags("em")
when the preferred document.getElementsByTagName isn't available.

var ems;
if (document.getElementsByTagName) {
ems = document.getElementsByTagName("em");
} else if (document.all && document.all.tags) {
ems = document.all.tags("em");
} else { // panic!
}
for (var i=0;i<ems.length;i++) {
ems[i].className = "italic"; // or "bold"
}

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4

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

Similar topics

7
by: varois83 | last post by:
Hi I am fairly new to PHP/mysql and was reading an online tutorial and learned that my short tags weren't enabled. At this time I have no need for them, my setup apache/mysql/php runs on my PC...
8
by: Paul | last post by:
This method: static void swap(int a, int b) { int c = a; a = b; b = c; } does not swap the values of a and b over. It doesn't work for String variables either. However the following method...
24
by: Day Bird Loft | last post by:
Web Authoring | Meta-Tags The first thing to understand in regard to Meta Tags is the three most important tags placed in the head of your html documents. They are the title, description, and...
3
by: Stewart | last post by:
Dear comp.lang.javascript, I have more than once wanted to manipulate the contents of select boxes dynamically, whilst the boxes contain <optgroup> tags. Manipulation of a select box containing...
2
by: Jeff | last post by:
Can I manipulate the properties of pure HTML controls (i.e. not server side controls) from my aspx.cs Page_Load event? If so, I don't see the control listed by intellisense. I gave the control a...
2
by: Steve Hershoff | last post by:
Hi everyone, I'm going to manipulate some XML files in my next project-- crawl through the tags, compare if file X has the same nodes as file Y, and if not, what the differences are and who's...
3
by: wibblefish | last post by:
Hello, I'm very new to PHP, but I'm trying to come up with a way in which I can store HTML tags, or ideally whole .css files in a database, then call these through a link on a webpage, and have...
1
by: rajakolluri | last post by:
Hi, This is Raja.....i am new joiner of this forum. here is my question. i strucked up in manipulating the tab indexes of image tags and buttons that are defined in html using java script. Here...
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:
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.