473,396 Members | 2,010 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,396 software developers and data experts.

Stuck in hell, surrounded by font elements

Somehow font elements are being added everywhere in my page, with size
set to 4. Maybe I'm just tired but I have no idea what's going on, even
weirder considering the page is XHTML 1.0 strict served with the proper
MIME type... heres some code:

var divs = document.getElementsByTagName("div");
for (var i=0; i<divs.length; i++) {
if (divs[i].className == "cwindow") {
windows.push( [ divs[i].title, document.body.removeChild(divs[i])]
);
i--;
}
}

for (var i=0; i<windows.length; i++) {
bodytext += "<div class='window_border'><div class='window_wrap'><div
class='window_header'><div class='window_header_content'>";
//Title
bodytext += windows[i][0];
bodytext += "</div></div><div class='window_body_border'><div
class='window_body' style='background-position:" +(
Math.round(Math.random()*800) )+ "px " +( Math.round(Math.random()*800)
)+ "px;'>";
//Body
bodytext += windows[i][1].innerHTML;
bodytext += "</div></div></div></div>";
}

Wherever I add the title and body from 'windows' it puts it inside a
font element with size of 4. Text is huge. It also adds it in other
places in the middle of a string asigned with innerHTML. I don't get it
and I'm giving up for sleep now, please point out my simple stupid
mistake.

HS

Nov 12 '06 #1
9 1415
ASM
ho**********@gmail.com a écrit :
Somehow font elements are being added everywhere in my page, with size
set to 4. Maybe I'm just tired but I have no idea what's going on, even
weirder considering the page is XHTML 1.0 strict served with the proper
MIME type... heres some code:
That bellow works fine for me :

<div class="cwindow"><h1>One</h1></div>
<div class="cwindow">Two</div>
<div class="other"><span style="color:blue">for</span></div>
<div class="cwindow"><span style="color:red">five</span></div>

<script type="text/javascript">
var divs = document.getElementsByTagName("div");
var windows = new Array();
var bodytext='';
for (var i=0; i<divs.length; i++) {
if (divs[i].className == "cwindow") {
windows.push([divs[i].title, document.body.removeChild(divs[i])]);
i--;
}
}

for (var i=0; i<windows.length; i++) {
bodytext += "<div class='window_border'><div class='window_wrap'>"+
"<div class='window_header'><div class='window_header_content'>";
//Title
bodytext += windows[i][0];
bodytext += "<\/div><\/div><div class='window_body_border'><div "+
"class='window_body' style='background-position:" +
(Math.round(Math.random()*800) )+ "px " +
( Math.round(Math.random()*800))+ "px;'>";
//Body
bodytext += windows[i][1].innerHTML;
bodytext += "<\/div><\/div><\/div><\/div>";
}
document.body.innerHTML = bodytext;
</script>

Wherever I add the title and body from 'windows' it puts it inside a
font element with size of 4. Text is huge. It also adds it in other
places in the middle of a string asigned with innerHTML.
it would have been better to cloneNode(true) the divs 'cwindow'
Nov 12 '06 #2


On Nov 12, 2:09 am, hobosales...@gmail.com wrote:
Somehow font elements are being added everywhere in my page, with size
set to 4. Maybe I'm just tired but I have no idea what's going on, even
weirder considering the page is XHTML 1.0 strict served with the proper
MIME type... heres some code:

<fonthas a tendency of cascading down the entire dom if it isn't
closed or is put in odd places.
ie: wrap a table in a <fontand all the <td>'s get <fontinserted
into them. It is incredibly annoying.

Nov 12 '06 #3
Unbelievable, the problem was a forum admin that thinks he's a web
designer. He added <font size=4to a forum category, without closing
it, so it ended up applied to most of the page. It was hard to track
down because it was hiding in an SQL database. So, sorry for wasting
bandwidth with what was really a non-javascript issue.

ASM wrote:
it would have been better to cloneNode(true) the divs 'cwindow'
Is there a difference between cloning and removing, and just using the
return value from removeChild()? I know that removing elements from a
list while stepping through it is maybe not so bright, but in this case
I don't see the problem?

HS

Nov 12 '06 #4
Richard Levasseur wrote:
<fonthas a tendency of cascading down the entire dom if it isn't
closed or is put in odd places.
ie: wrap a table in a <fontand all the <td>'s get <fontinserted
into them. It is incredibly annoying.
Oh boy is it ever....

It's inspired me to write a perl script that looks through a site for
pages with a valid XHTML doctype , and adds deprecated markup in random
places.

HS

Nov 12 '06 #5
ho**********@gmail.com wrote:
it would have been better to cloneNode(true) the divs 'cwindow'

Is there a difference between cloning and removing, and just using the
return value from removeChild()? I know that removing elements from a
list while stepping through it is maybe not so bright, but in this case
I don't see the problem?
I was giving this more thought, and wouldn't it be more efficient to
use the returned value from removeChild(), than the extra memory
involved in a deep copy of the element only to remove it anyway?

HS

Nov 12 '06 #6
ASM
ho**********@gmail.com a écrit :
ho**********@gmail.com wrote:
>>it would have been better to cloneNode(true) the divs 'cwindow'
Is there a difference between cloning and removing, and just using the
return value from removeChild()? I know that removing elements from a
list while stepping through it is maybe not so bright, but in this case
I don't see the problem?
As I found no problem in my test with inneHTML, I can't say more.
I was giving this more thought, and wouldn't it be more efficient to
use the returned value from removeChild(), than the extra memory
involved in a deep copy of the element only to remove it anyway?
As I don't understand what you try to do ...
Tacking content of divs of class 'something' to put it in others divs of
class 'something-else' ...

Why not to append directly the divs of class 'something' after having
changed this class in 'something-else' in your group of others divs (I
don't know their use)
<div class="cwindow" title="un">
<h1>One</h1>
</div>
<div class="other" title="number 2">
<span style="color:red">two</span>
</div>
<div class="cwindow" title="trois">
<font size="6" color="maroon">Three</font>
<tt>three</tt>
</div>
<div class="other">
<span style="color:blue">for</span>
</div>
<div class="cwindow" title="red span">
<span style="color:red">five</span>
</div>
<script type="text/javascript">

function newDiv(classe) {
var D = document.createElement('div');
D.className = classe;
return D;
}

var divs = document.getElementsByTagName("div");
for (var i=0; i<divs.length; i++) {
if (divs[i].className == "cwindow") {
var R = newDiv('window_border');
var S = newDiv('window_wrap');
var T = newDiv('window_header');
var U = newDiv('window_header_content');
U.innerHTML = divs[i].title;
T.appendChild(U);
S.appendChild(T);
T = newDiv('window_body_border');
divs[i].className = 'window_body';
divs[i].style.backgroundPosition =
(Math.round(Math.random()*800) )+ "px " +
( Math.round(Math.random()*800))+ "px";
T.appendChild(divs[i]);
S.appendChild(T);
R.appendChild(S);
document.body.appendChild(R);
}
}
</script>

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Nov 12 '06 #7
ASM wrote:
As I don't understand what you try to do ...
Tacking content of divs of class 'something' to put it in others divs of
class 'something-else' ...

Why not to append directly the divs of class 'something' after having
changed this class in 'something-else' in your group of others divs (I
don't know their use)
I was thinking more theoretically, but I have PHP generated divs which
are content for "windows", which javascript removes from the page so
that a loader screen can appear while the rest of the HTML and JS is
downloaded, then it creates windows and adds the content from the
original page. I can't append directly to the other div because it
doesn't exist yet.

Nov 13 '06 #8
ASM
ho**********@gmail.com a écrit :
ASM wrote:
>As I don't understand what you try to do ...
Tacking content of divs of class 'something' to put it in others divs of
class 'something-else' ...

Why not to append directly the divs of class 'something' after having
changed this class in 'something-else' in your group of others divs (I
don't know their use)

I was thinking more theoretically, but I have PHP generated divs which
are content for "windows", which javascript removes from the page so
that a loader screen can appear while the rest of the HTML and JS is
downloaded, then it creates windows and adds the content from the
original page. I can't append directly to the other div because it
doesn't exist yet.
No, I understood your displayers groups of divs don't exist, in what I
suggested these groups are created each time it is necessary.
Of course, you can make a function to do all that job; this function
being launched after complete loading of the php file.
Appending on the fly directly in groups the targeted divs one by one is
equivalent to move them one by one (no need to remove and remember all
them)

onload = function() {
var divs = document.getElementsByTagName("div");
for (var i=0; i<divs.length; i++)
if( ... etc ...
}
But that will not fix the problem of absent font closing tag :-)

Is tag 'font' allowed in XHTML 1.0 strict ?

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Nov 13 '06 #9
ASM wrote:
Is tag 'font' allowed in XHTML 1.0 strict ?
Noooooo... it's like taking a 1982 Toyota Corolla with blown rings and
missing catalytic converter in for an emissions test. The font tag is
evil, useless, obsolete, and only used by amateurs that don't know any
better (like my users apparently).

HS

Nov 14 '06 #10

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

Similar topics

6
by: Csaba2000 | last post by:
How do I detect when the font size has been changed (especially by user action: either Ctrl+Scroll wheel or View/Text Size)? This is just for use on IE 5.5+, but it would be great if there was a...
7
by: Phil Powell | last post by:
Code: <!-- script src="/js/val_header.js"></script --> <style> <!-- BODY { scrollbar-3d-light-color:#eeeedd; scrollbar-arrow-color:#000000; scrollbar-base-color:#000000;...
4
by: Csaba Gabor | last post by:
What I'd like to do is to be able to set the font of a textarea element to the same font that another element is using (say, for example, an <INPUT type=text ...> element, but if that's a no go,...
9
by: Dr John Stockton | last post by:
Assuming default set-ups and considering all reasonable browsers, whatever that may mean, what should an author expect that his readers in general will see (with visual browsers) for a page with...
16
by: maya | last post by:
I have heard so much preaching here about how font sizes should be set as percentages so users can change font-sizes on their browsers... ok, so now at work am working on a site where we need to do...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
8
by: scrm | last post by:
Hi there - I've just redesigned my site (http://scandal.org ) as a simple photo gallery. I'm having some trouble getting it to display as I'd like on IE (7.0, Win). I'd like your advice on a few...
14
by: Roedy Green | last post by:
Is there a shortcut way to define the default font family (and characteristics) to be applied to all styles? -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...

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.