PDA

View Full Version : help with simple DOM


ddolddolee82
04-21-2006, 08:24 PM
I am trying to use a DOM trick with images. Anyway, I wrote this short lines of codes to test it. This seems to work in internet explorer but it doesn't in firefox. Is there something wrong with it?



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr" />
<title>Untitled Document</title>
<script type='text/javascript'>
function original () {
document.getElementById('image').innerHTML = '<p>replaced</p>';
}

</script>
</head>

<body>
<span id='image'><p>replace this part</p></span>
<p><a href onclick='original()'>click</a></p>
</body>
</html>

Vege
04-21-2006, 08:53 PM
http://www.javascriptkit.com/javatutors/dynamiccontent4.shtml

innerHTML is considered depracated by W3C
try the second example on that page.

RysChwith
04-24-2006, 09:32 AM
More accurately: innerHTML has never been part of the spec. It was a convenience property which has been widely adopted; the official W3C equivalent are the DOM methods.

As to the issue you're having, I can see two possible causes. The first, which seems less likely to actually be causing the problem, is the <p> inside of a <span> You can't have a block-level element inside of an inline element. Also, in XHTML, you can't have an inline element that isn't contained within a block-level element.

What strikes me as more likely the cause of the problem is the <a> tag's href attribute. It needs to have a value. For your purposes, setting it to "javascript:void" should suffice.

Rys