473,396 Members | 1,676 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.

Parsing HTML Tags

How to parse HTML Tags in javascript?
Aug 16 '07 #1
7 2175
acoder
16,027 Expert Mod 8TB
Could you give an example.

You can use document.getElementsByTagName.
Aug 16 '07 #2
Could you give an example.

You can use document.getElementsByTagName.
In web pages I design there are some sub links in addition to the Main Links.When I click on the sub links I want to lord the contents to a particular location inside the page.So I am using document.getElementById("content_area").innerHTML= "bla...bla..bla..."
When I am using doing this I pass HTML tags too to the innerHTML property in addition to normal texts.To work this properly in a browser all the white spaces within the hTML tags have to be removed.

For example...

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("content_area").innerHTML='<table width="300"><tr><td width="10">&nbsp;</td><td width="290" align="left" valign="top" class="content">some text goes here</td></tr></table>';
  2.  
Cant I do it in this way?

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("content_area").innerHTML='<table width="300">
  2. <tr>
  3. <td width="10">&nbsp;</td>
  4. <td width="290" align="left" valign="top" class="content">some text goes here</td>
  5. </tr>
  6. </table>';
  7.  
Coz it is a real headache to remove white spaces if the content is very big.
Aug 17 '07 #3
acoder
16,027 Expert Mod 8TB
See this page. You can create a table and add rows and cells without having to worry about whitespace.

Please post code using CODE tags. Thanks!
Aug 17 '07 #4
ak1dnar
1,584 Expert 1GB
If there is a Solution to this Issue I also like to learn really.
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("content_area").innerHTML='<table width="300">
  2. <tr>
  3. <td width="10"> 
  4. <td width="290" align="left" valign="top" class="content">some text goeshere
  5. </tr>
  6. </table>';
Currenty When trying to assign some HTML tags with this format FireBug is Giving this Error message.

Expand|Select|Wrap|Line Numbers
  1. unterminated string literal
  2. [img]chrome://firebug/content/blank.gif[/img]document.getElementById("content_area").innerHTML='<table width="300">\n
  3.  
BUT what I am trying to say actually, the Problem is NOT with white spaces here.
We are Not Closing the Javascript lines by putting ";" so that unterminated string literal Error is Getting.


For Now this is Only Solution for this.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Untitled Document
  4. <script language="JavaScript" type="text/javascript">
  5. function setText(){
  6. var contents;
  7. contents='<table width="300">';
  8. contents +='<tr>';
  9. contents +='<td width="10"> ';
  10. contents +='<td width="290" align="left" valign="top" class="content">some text goeshere';
  11. contents +='</tr>';
  12. contents +='</table>';
  13. document.getElementById("content_area").innerHTML=contents;
  14. }
  15. </script>
  16. </head>
  17.  
  18. <body>
  19. <div id="content_area">Nothing
  20.  
  21. <a href="#" onclick="setText()">Click Me
  22. </body>
  23. </html>
  24.  
But Its Hard to make it when the HTML coding area is too much.
Aug 20 '07 #5
acoder
16,027 Expert Mod 8TB
...
For Now this is Only Solution for this.
...But Its Hard to make it when the HTML coding area is too much.
To avoid this mess, you should consider using the DOM methods for appending elements instead of using innerHTML. See the linked article in my previous post.
Aug 20 '07 #6
To avoid this mess, you should consider using the DOM methods for appending elements instead of using innerHTML. See the linked article in my previous post.
Ok thank you very much for the replies.But what I actually want to do is not to generate a dynamic table but to display some contents which are already created.I have arranged all my contents(texts,images,links,etc....) in tables as I use tables to arrange contents when I design web pages.So that what I want to do is when clicking a link/button those stuffs should be displayed within a <td> or <div> using javascript.That is why I am using the innerHTML property of the particular <td> or <div> which I have assigned a id.
Aug 21 '07 #7
acoder
16,027 Expert Mod 8TB
Ok thank you very much for the replies.But what I actually want to do is not to generate a dynamic table but to display some contents which are already created.I have arranged all my contents(texts,images,links,etc....) in tables as I use tables to arrange contents when I design web pages.So that what I want to do is when clicking a link/button those stuffs should be displayed within a <td> or <div> using javascript.That is why I am using the innerHTML property of the particular <td> or <div> which I have assigned a id.
If you possibly can, you should try to use CSS for layout rather than tables.

If it's already created, there's no need to use innerHTML. Just append instead.
Aug 21 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Peter Sprenger | last post by:
Hello, I hope somebody can help me with my problem. I am writing Zope python scripts that will do parsing on text for dynamic webpages: I am getting a text from an oracle database that contains...
0
by: Fuzzyman | last post by:
I am trying to parse an HTML page an only modify URLs within tags - e.g. inside IMG, A, SCRIPT, FRAME tags etc... I have built one that works fine using the HTMLParser.HTMLParser and it works...
3
by: djdave | last post by:
My problem is that i need an algorithm parse parse HTML. For an HTML page, my script has to parse all tags to get all forms values, even if there is frame, iframe, ... How can i do such a script ?...
3
by: Pir8 | last post by:
I have a complex xml file, which contains stories within a magazine. The structure of the xml file is as follows: <?xml version="1.0" encoding="ISO-8859-1" ?> <magazine> <story>...
1
by: Xarky | last post by:
Hi, I'm newbie to XML parsing. I have the following XML document and would like to extract the age for a specific person. Can you please give me some specific links, of how I can achieve this....
1
by: yonido | last post by:
hello, my goal is to get patterns out of email files - say "message forwarding" patterns (message forwarded from: xx to: yy subject: zz) now lets say there are tons of these patterns (by gmail,...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
4
by: Neil.Smith | last post by:
I can't seem to find any references to this, but here goes: In there anyway to parse an html/aspx file within an asp.net application to gather a collection of controls in the file. For instance...
1
by: prakash280681 | last post by:
how to get the correct result when we parse the xml code.Because in parsing when it get the syntax like < and & it break it and forward.. i use the code---- <?php $xml_file = "news.xml"; ...
5
by: moddster | last post by:
Hi Guys. I am a newbie to perl and need some help with a problem. PROBLEM: I have to parse an HTML file and get rid of all the HTML tags and count the number of sumbissions a person has through...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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.