p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   Read HTML comments with Javascript (http://p2p.wrox.com/showthread.php?t=20598)

benburrows October 29th, 2004 10:10 AM

Read HTML comments with Javascript
Does anyone know how to read HTML comments with javascript?
ie. I have a section in my HTML like
<div id="test">
Some words

I want to get "some words" into a javascript variable.
I need this to be cross browser compatable.
I have read books and looked on the net and I think what I want is possable but I cannot make it work.

Imar October 29th, 2004 11:50 AM

Hi Ben,

You can use the innerHTML property of the <div> tag like this:


You'll need to do some string parsing to get rid of the comment tags, but that shouldn't be too hard.



richard.york October 29th, 2004 11:59 AM

If you just want to set aside some text, it might be easier to use the CSS display property.

<div id='test' style='display: none;'>
    Some words.

<script type='text/javascript'>
    // Then just access the contents of that div like this

The text in the <div> isn't visible in CSS capable browsers.


[http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail

benburrows October 29th, 2004 12:50 PM

Thanks for the sugestion, works a treat :-)
Can't beleive I did not try that, I got distracted by trying to directly get at the comment tag itself.

Thanks for the Sugestion. Unfortunately I can't just "hide" the text, I need it ignored completely until I want to use it.


All times are GMT -4. The time now is 10:46 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.