PDA

View Full Version : What's wrong with this javascript code?


aooga
05-04-2009, 10:49 PM
<script type="text/javascript">
function a() {
document.getElementById('2').innerHTML = "<p onclick='b()'>a</p>";
}
function b() {
document.getElementById('2').innerHTML = "hello"; // this doesn't work
document.getElementById('3').innerHTML = "hello"; // this does
}
</script>

<p id='1' onclick='a()'>1</p>
<p id='2' onclick='a()'>2</p>
<p id='3' onclick='a()'>3</p>

abduraooft
05-05-2009, 10:21 AM
Validate your code (http://validator.w3.org/#validate_by_input) and fix all errors in your markup first.