Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7918567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:33:12+00:00 2026-06-03T15:33:12+00:00

I have the following page: <html> <head> <title>Test</title> <script type=text/javascript> function BuildTree() { var

  • 0

I have the following page:

<html>
<head>
    <title>Test</title>
    <script type="text/javascript">
        function BuildTree() {
            var total = 0;
            var pages = document.getElementsByTagName('custom:page');
            var questions = pages[0].getElementsByTagName('custom:question');
            for (var i = 0; i < questions.length; ++i) {
                var question = questions[i];
                var val = question.getAttribute('value')
                total += val;
            }
            alert("Total: " + total);
        };
    </script>
</head>
<body>
    <custom:pages>
        <custom:page>
            <custom:question  value="1">aaa</custom:question>
            <custom:question  value="2">bbb</custom:question>
            <custom:question  value="3">ccc</custom:question>
        </custom:page>
        <custom:page>
            <custom:question  value="1">aaa</custom:question>
            <custom:question  value="2">bbb</custom:question>
            <custom:question  value="3">ccc</custom:question>
        </custom:page>
    </custom:pages>
    <input id="btnTest" type="button" value="Test" onclick="BuildTree();" />
</body>
</html>

When I click the Test button in IE the result is 0, when I click it in FF the result is 0123.

How can I get the same result in both browsers? i.e. ‘0123’.

Note that I’ve trimmed this down to as simple an example as possible. I cannot use jquery or any third party libraries, I need a pure Javasscript solution. I also cannot change the custom: tags.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T15:33:14+00:00Added an answer on June 3, 2026 at 3:33 pm
    <html xmlns:custom="http://www.test.com">
    <head>
        <title>Test</title>
        <script type="text/javascript">
            // We want to find all the question tags withing a page tag
            // getElementsByTagName works fine when using standard HTML tags within each other
            function BuildTree() {
                var total = 0;
                // These two do not work in IE but do work in FF
                //var pages = document.getElementsByTagName('custom:page');
                //var questions = pages[0].getElementsByTagName('custom:question');
    
                // These only work in FireFox (and require a namespace)
                //var pages = document.getElementsByTagNameNS('http://www.test.com', 'page'); // FF only
                //var questions = pages[0].getElementsByTagNameNS('http://www.test.com', 'question'); // FF only
    
                // Adding a namespace ' xmlns:custom="http://www.test.com"' to the document and removing the 'custom:' from the search works correctly
                var pages = document.getElementsByTagName('page');
                var questions = pages[0].getElementsByTagName('question');
    
                for (var i = 0; i < questions.length; ++i) {
                    var question = questions[i];
                    var val = question.getAttribute('value')
                    total += val;
                }
                alert("Total: " + total);
            };
        </script>
    </head>
    <body>
        <custom:pages>
            <custom:page>
                <custom:question value="1">aaa</custom:question>
                <custom:question value="2">bbb</custom:question>
                <custom:question value="3">ccc</custom:question>
            </custom:page>
            <custom:page>
                <custom:question value="1">aaa</custom:question>
                <custom:question value="2">bbb</custom:question>
                <custom:question value="3">ccc</custom:question>
            </custom:page>
        </custom:pages>
        <input id="btnTest" type="button" value="Test" onclick="BuildTree();" />
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my HTML Code <html> <head> <title> Test Page </title> <script type='text/javascript'> function
I have the following test ASPX page: <head runat=server> <title></title> <script src=js/jquery-1.2.6.min.js type=text/javascript></script> <script
Assuming I have the following ASP.NET HTML Code: <html> <head><title>Test Page</title></head> <body id=bodyID> <asp:Label
I have the following HTML Code <%@ Page Language=C# %> <html> <head> <title></title> </head>
I have the following page: <!DOCTYPE HTML> <html> <head> <meta charset=utf-8> <title>Untitled Document</title> </head>
I have the following markup inside a master page <html xmlns=http://www.w3.org/1999/xhtml > <head runat=server>
I have the following jsp file <%@ page language=java contentType=text/html; charset=ISO-8859-1 pageEncoding=ISO-8859-1%> <%@ page
I have the following HTML on a Jquery Mobile Page: <div data-role=controlgroup data-type=horizontal class=panelSwitcher>
I have the following HTML on my web page: <input id=htmlEdit type=checkbox/> Once the
I have the following simple script on a page <!DOCTYPE html PUBLIC -//W3C//DTD XHTML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.