Javascript In Html
i am using javascript to change the text of div tag on run time. how can this be done.. my div tag is as:
&l
Solution 1:
It should be innerHTML
. innerHTM
is not a javascript function.
Solution 2:
- You don't get a magic variable just by having an element with an id.
var something = document.getElementById('some-id')
- The property is called
innerHTML
notinnerHTM
innerHTML
is a string variable not an function. Assign a value to it with=
, don't try to call it with()
Solution 3:
functionedit1() {
alert('you are in edit1');
document.getElementById('topdiv').innerHTML = 'hello';
}
and with proper error handling:
functionedit1() {
alert('you are in edit1');
var topDiv = document.getElementById('topdiv');
if (topDiv != null) {
topDiv.innerHTML = 'hello';
} else {
alert('topdiv is nowhere to be found in this DOM');
}
}
Solution 4:
Solution 5:
To get the div
you should use document.getElementById('topdiv')
. There is indeed a WebKit feature, that elements with an ID are automatically expanded as global variables, but it's highly questionable, that this becomes mainstream.
Then, innerHTM
should read innerHTML
, and you assign directly:
foo.innerHTML = "hi there"
Post a Comment for "Javascript In Html"