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 8397559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:49:20+00:00 2026-06-09T20:49:20+00:00

Given the following code: <!DOCTYPE html> <!– HTML5 –> <html> <head> <meta http-equiv="Expires" content="Fri,

  • 0

Given the following code:

<!DOCTYPE html> <!-- HTML5 -->
<html>
    <head>
        <meta http-equiv="Expires" content="Fri, Jan 01 1900 00:00:00 GMT">
        <meta http-equiv="Pragma" content="no-cache">
        <meta http-equiv="Cache-Control" content="no-cache">
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <meta http-equiv="content-language" content="en">
        <title>Untitled</title>
        <script type='text/javascript'>
            function createTableRow() {
                var tr = document.createElement("tr");
                var strWork = "<tr onmouseover='this.style.cursor=\"pointer\";'";
                strWork += " onmouseout='this.style.cursor=\"auto\";'";
                strWork += " onclick='ShowClick(this);'";
                strWork += " id='TestCell'><td>Test!</td></tr>";
                alert(strWork);
                tr.outerHTML = strWork;
                return tr;
            }

            function BuildTable() {
                var table = document.createElement("table");
                table.appendChild(createTableRow());
                return table;
            }

            function ShowClick(obj) {
                alert(obj.id);
            }
        </script>
    </head>
    <body onload='alert(BuildTable().outerHTML);'>
    &nbsp;
    </body>
</html>

The first "alert" dialog shows the tag as I want it to be formed, however, the "onload=alert" line returns the result "<table><tr></tr></table>".

What am I doing wrong? Why aren’t these events binding to the TR tag?

Also, I’d like to add that I originally assigned the events using JavaScript i.e.:

tr.onclick = function() { ShowClick(this); };

But had the exact same result…

I really don’t get it, and I can’t find any discussion about the problem anywhere… any help would be greatly appreciated!

  • 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-09T20:49:22+00:00Added an answer on June 9, 2026 at 8:49 pm

    Your code throws a NO_MODIFICATION_ALLOWED_ERR in the JavaScript console. The W3C spec has this to say:

    [element.outerHTML] throws a NO_MODIFICATION_ALLOWED_ERR exception if the parent of the element is the Document node.

    The same thing happens in your code. You’re setting the tr‘s outerHTML before you’ve appended it to another Node (e.g. the table). That’s why its outerHTML can’t be changed.

    The easiest solution is not to use outerHTML. Try your original approach:

    function createTableRow() {
      var tr = document.createElement('tr');
      tr.onmouseover = function() {
        this.style.cursor = 'pointer';
      };
      tr.onmouseout = function() {
        this.style.cursor = 'auto';
      };
      tr.onclick = function() {
        ShowClick(this);
      };
      tr.id = 'TestCell';
      tr.innerHTML = '<td>Test!</td>';
      return tr;
    }
    

    Note that when you alert (or console.log) the table‘s outerHTML, you’ll see something like this:

    <table><tr id="TestCell"><td>Test!</td></tr></table> 
    

    But don’t let that fool you. The event handlers don’t show up, but that’s because they are attached directly to the DOM node, thus bypassing the HTML. Rest assured that they work perfectly.

    To see for yourself, try this live demo: jsbin.com/oterit/1/edit

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

given the following code <!DOCTYPE html> <html> <head> <title>show stats</title> <style> span.main { position:relative;
Given the following code var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, {'Content-Type':
Given the following code $c= new SoapClient('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL'); $usa = USD; $eng = GBP; doing
Given following html code: <ul> <li> <a href=somelink> <span class='someIconCss'></span> <span>home</span> </a> </li> [possibly
Given the following HTML code, why is it that when this document is printed
Given the following code: $(.force-selection).blur(function() { var value = $('matched-item').val(); //check if the input's
Given the following code: final class retVal { int photo_id; } Gson gson =
Given the following code: function Person(firstName, lastName) { this.FirstName = firstName; this.LastName = lastName;
Given the following code. EventLoopScheduler scheduler = new EventLoopScheduler(ts => new Thread(ts)); BehaviorSubject<int> subject
Given the following code below, how can I have it modified such that it

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.