Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > HTML in Javascript

Reply
Thread Tools

HTML in Javascript

 
 
yuqiaoyan@gmail.com
Guest
Posts: n/a
 
      07-09-2007
Hi,

I'm not very familiar with javascript, but I found a script that would
really help with my site. The javascript tool is an image viewer. When
a user clicks on an image, it displays content for the user. But I
can't seem to get the browser to display the HTML code correctly even
though the HTML code works when it's not within javascript code. It
doesn't seem to recognize the valign = 'top' and the text-align =
'left' code. It displays the text in the center of the TD element.
Does anyone have any idea how to force the browser to recognize the
valiang and text-align?

Thanks in Advance!

Imagespace is a div

imagespace.innerHTML = "<table style='width: 500px'>"+
"<tr style='height:200px'>"+
"<td style='width:280px'><img

alt=''src='test.jpg' width='279'

height='200' />&nbsp;</td>"+
" <td valign='top'

text-align='left'><strong>Title:</strong> Test Test<br />"+
" <strong>Category:</strong> Test Test<br />"+
" <strong>Author:</strong> Test Test<br />"+
" <strong>Date:</strong> 5/25/07</td>"+
"</tr>"+
"<tr>"+
" <td colspan='2'><strong><br />"+
" Description: </strong>Testing................"+
" Testing...................................td>"+
"</tr>"+
"</table>"

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      07-09-2007
On Jul 9, 4:18 pm, yuqiao...@gmail.com wrote:
> Hi,
>
> I'm not very familiar with javascript, but I found a script that would
> really help with my site. The javascript tool is an image viewer. When
> a user clicks on an image, it displays content for the user. But I
> can't seem to get the browser to display the HTML code correctly even
> though the HTML code works when it's not within javascript code. It
> doesn't seem to recognize the valign = 'top' and the text-align =
> 'left' code.


valign is deprecated in HTML 4, text-align is not a valid HTML
attribute, see below.

> It displays the text in the center of the TD element.
> Does anyone have any idea how to force the browser to recognize the
> valiang and text-align?
>
> Thanks in Advance!
>
> Imagespace is a div
>
> imagespace.innerHTML = "<table style='width: 500px'>"+
> "<tr style='height:200px'>"+
> "<td style='width:280px'><img
>
> alt=''src='test.jpg' width='279'
>
> height='200' />&nbsp;</td>"+


If this is supposed to be HTML, forget the faux XMTL markup. To an
HTML parser, it is just junk.


> " <td valign='top'
>
> text-align='left'><strong>Title:</strong> Test Test<br />"+


text-align is not a valid HTML attribute name, it is a CSS property
name. Anyway, align left is the default, so why bother?

<td style="text-align: left;" ... >

I have no idea why the text is being centered unless you have some CSS
elsewhere that is doing it.


--
Rob

 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      07-09-2007
wrote on 09 jul 2007 in comp.lang.javascript:

> Hi,
>
> I'm not very familiar with javascript, but I found a script that would
> really help with my site. The javascript tool is an image viewer. When
> a user clicks on an image, it displays content for the user. But I
> can't seem to get the browser to display the HTML code correctly even
> though the HTML code works when it's not within javascript code. It
> doesn't seem to recognize the valign = 'top' and the text-align =
> 'left' code.


See below, and use css, not code from the 1990's

> It displays the text in the center of the TD element.
> Does anyone have any idea how to force the browser to recognize the
> valiang and text-align?
>
> Thanks in Advance!
>
> Imagespace is a div


"Is" is impossible,
it is either the id or the name of a <div>

> imagespace.innerHTML = "<table style='width: 500px'>"+


Think cross browser compatibility,

use:

document.getElementById('Imagespace').innerHTML = ....

[but do not use innerHTML here at all, see below]

> "<tr style='height:200px'>"+
> "<td style='width:280px'><img
>
> alt=''src='test.jpg' width='279'
>
> height='200' />&nbsp;</td>"+
> " <td valign='top'
>
> text-align='left'><strong>Title:</strong> Test Test<br />"+
> " <strong>Category:</strong> Test Test<br />"+
> " <strong>Author:</strong> Test Test<br />"+
> " <strong>Date:</strong> 5/25/07</td>"+
> "</tr>"+
> "<tr>"+
> " <td colspan='2'><strong><br />"+
> " Description: </strong>Testing................"+
> " Testing...................................td>"+
> "</tr>"+
> "</table>"


Do not use those pesty anderror prone string litterals
you would need to .innerHTML for this.

Better build [several?] <div>'s in straight html,
that are style='display:none;' -ed by default,
and can be shown by

document.getElementById('myDiv7').style.display = 'block';

[or use visibility visible/hidden, if you want to (p)reserve the space]

======================

> <br />


Is this XML? I think not, so use:

<br>

===========

> <img alt=''src='test.jpg' width='279' height='200' />


setting an empty alt='' has no use
use css
do not use />
use:

<img src='test.jpg' style='width:279px;height:200px;'>



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
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
firefox html, my downloaded html and firebug html different? Adam Akhtar Ruby 9 08-16-2008 07:55 PM
Load HTML in text strings into HTML parser in Javascript David Virgil Hobbs HTML 2 04-09-2006 01:21 PM
How to read the BODY of HTML file from another HTML file using javascript? Dhanasankar S via DotNetMonster.com ASP .Net 1 02-28-2005 05:51 PM
How to read the BODY of HTML file from another HTML file using javascript? Dhanasankar S via DotNetMonster.com ASP .Net 0 02-26-2005 10:58 AM
help! javascript inline of an HTML to open an HTML in a target window Lucy Javascript 6 01-01-2004 07:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57