Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Manipulate all tags

Reply
Thread Tools

Manipulate all tags

 
 
Fabian
Guest
Posts: n/a
 
      11-07-2003
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

 
Reply With Quote
 
 
 
 
Fabian
Guest
Posts: n/a
 
      11-07-2003
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

 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      11-07-2003
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)
 
Reply With Quote
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      11-07-2003
"Fabian" <> 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 -
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Manipulate style/classes after all controls are being created - how? DC ASP .Net 2 01-31-2008 01:24 PM
How to manipulate all user controls with custom property X set to Y? Ken Fine ASP .Net 0 01-05-2007 06:08 AM
All style tags after the first 30 style tags on an HTML page are not applied in Internet Explorer Rob Nicholson ASP .Net 3 05-28-2005 03:11 PM
To manipulate or not to manipulate Dave C++ 1 01-22-2005 10:52 PM
RegEx to find CFML tags nested in HTML tags Dean H. Saxe Perl 0 01-03-2004 06:11 PM



Advertisments