Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: setAttribute()

  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setAttribute()

    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript">
    function loaded()
    {
    	// create elements
    	var table = document.createElement('table');
    	var tbody = document.createElement('tbody');
    	var tr_a = document.createElement('tr');
    	var tr_b = document.createElement('tr');
    	var td_a = document.createElement('td');
    	var td_b = document.createElement('td');
    	var td_c = document.createElement('td');
    	var text = document.createTextNode('hello world');
    	// attributes
    	table.setAttribute('border','1');
    	td_c.setAttribute('colspan','2'); // ?!?@#$!
    	// append row 1
    	td_a.innerHTML = td_b.innerHTML = 'foo';
    	tr_a.appendChild(td_a);
    	tr_a.appendChild(td_b);
    	tbody.appendChild(tr_a);
    	tbody.appendChild(tr_b);
    	// append row 2s
    	td_c.innerHTML = 'bar';
    	tr_b.appendChild(td_c);
    	table.appendChild(tbody);
    	document.getElementById('target').appendChild(table);	
    };
    </script>
    </head>
    
    <body onload="loaded();">
    <div id="target"></div>
    </body>
    </html>

  • #2
    WA
    WA is offline
    Administrator
    Join Date
    Mar 2002
    Posts
    2,596
    Thanks
    2
    Thanked 19 Times in 18 Posts
    Hi:
    Please edit your thread and more clearly state the nature of it. Is this a question? Thanks,
    - George
    - JavaScript Kit- JavaScript tutorials and 400+ scripts!
    - JavaScript Reference- JavaScript reference you can relate to.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •