Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing a function to setAttribute()

Status
Not open for further replies.

phpPete

Programmer
Feb 25, 2002
88
US
In a JS dynamically generated table, if I do this:
Code:
var currentRow = document.createElement('tr');
currentRow.setAttribute('onclick', 'nukeNode(this.id);');

I get no response. When i replace the function nukeNode() with an alert for testing purposes, the event handler is fired not when i click the table row, but when i click the button which builds the table.

Here's the nukeNode() function definition
Code:
function nukeNode(nam)
  {
    var targetNode =  document.getElementsByTagName('body').item(0);
    targetNode.removeChild( nam );    
  }

How can i get this so that clicking on any table row will remove that row from the table?
 
You cant use setAttribute to set event handlers in javascript on an element.

Im sure you could use the Table object model to delete rows as you click on them
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top