473,832 Members | 2,132 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4644
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.javas cript:
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.ta gs("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.getEle mentsByTagName( "em");
for (var i=0;i<ems.lengt h;i++) {
ems[i].style.fontStyl e = "italic";
ems[i].style.fontWeig ht = "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.getEle mentsByTagName( "em");
for (var i=0;i<ems.lengt h;i++) {
ems[i].className = "italic"; // or "bold"
}

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

var ems;
if (document.getEl ementsByTagName ) {
ems = document.getEle mentsByTagName( "em");
} else if (document.all && document.all.ta gs) {
ems = document.all.ta gs("em");
} else { // panic!
}
for (var i=0;i<ems.lengt h;i++) {
ems[i].className = "italic"; // or "bold"
}

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.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
7111
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 just to test code. Shall I enable short tags or not? Windows XP pro PHP 4
8
2565
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 does swap the first two
24
3565
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 keyword meta-tags. If you are missing any of these meta-tags you are missing the boat. If you use the following meta-tag formula, and you are not trying to deceive the spiders, I guarantee you will succeed in increasing your placement in the...
3
15627
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 only <option> tags is fairly easy and there is plenty of material on the net to assist with this. However, I have searched long and found the material on the subject of <optgroup> to be sparse, with a few posts here & there, but basically you're...
2
2253
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 unique ID to boot. Is what I'm trying impossible unless you are using a server side control? Thanks
2
1184
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 missing what. I'll also be comparing values between nodes in the two files, for when both documents do have the same named nodes. What .Net classes should I be looking at to accomplish these tasks? Thanks a bunch.
3
3152
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 the formatting change as a result. I have managed to get as far as beign able to upload all the schpeel i need into the database, but can't get my head around how to parse this into html via PHP Any help much appreciated! Wibble!
1
1743
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 is the kind of logic needs to be implemented. i have main screen with 3 sub sections. 1. main screen has 3 images tags and 3 submit button's. the Tab order that these elements follows : first 3 image butons and 3 submit buttons and even based...
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10781
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
10212
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9320
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...
1
7753
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
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
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4421
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3078
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.