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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Appending to TD (DOM) 1

Status
Not open for further replies.

kdutta

Programmer
Feb 6, 2008
1
CA
Hi:

I need to add HTML element to existing TD. For example my existing TD has DIV, Image etc and on click I want to add to same TD an image contol.
i.e. TD(Div, image)
after click TD(Div, image, image)
I have tried a lot of options like cloning existing TD and then creating a new one and appending nodes. But I have no success.

Anysuggestions, any clues are welcome.

Thankyou so much in advance,
Kris
 
The easiest (and probably fastest) way is just to completely skip the dom methods and use innerHTML.

Check out this test by clicking on the first table element (the one with a value of 1)
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

function append(obj) {
   obj.innerHTML = obj.innerHTML + '<br /><a href="[URL unfurl="true"]http://www.google.com">google</a>';[/URL]
}

</script>
<style type="text/css"></style>
</head>
<body>

<table id="t" border="1">
   <tr>
      <td onclick="append(this)">1</td>
      <td>2</td>
   </tr>
   <tr>
      <td>3</td>
      <td>4</td>
   </tr>
</table>

</body>
</html>

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top