HTML manipulations without reloading page

Q

Qu0ll

I am new to JavaScript programming and I'm looking for a way to manipulate
the contents of an HTML page without having to load or reload the whole
page. I would like there to be a "static" region of the page which doesn't
change and then other regions where I can dynamically alter the contents
(only text at this stage) from JavaScript either from a command initiated
when the user clicks a button or from a Java applet.

For example, there may be a heading in the page with the text "News for
January 1". I would like to be able to change that to "News for January 2"
without reloading the other content of the page.

Can this be done with JavaScript?

--
And loving it,

-Q
_________________________________________________
(e-mail address removed)
(Replace the "SixFour" with numbers to email me)
 
M

Martin Honnen

Qu0ll said:
For example, there may be a heading in the page with the text "News for
January 1". I would like to be able to change that to "News for January
2" without reloading the other content of the page.

Can this be done with JavaScript?

Yes, nowadays common browsers build a nearly complete document object
model and allow to manipulate that e.g.

<h1 id="someId">News for January 1</h1>

var element = document.getElementById('someId');
if (element != null && element.firstChild && element.firstChild.nodeType
== 3) {
element.firstChild.nodeValue = 'News for January 2';
}

The element does not need to have an id, there are other ways like
getElementsByTagName to find elements.
 
Q

Qu0ll

Martin Honnen said:
Yes, nowadays common browsers build a nearly complete document object
model and allow to manipulate that e.g.

<h1 id="someId">News for January 1</h1>

var element = document.getElementById('someId');
if (element != null && element.firstChild && element.firstChild.nodeType
== 3) {
element.firstChild.nodeValue = 'News for January 2';
}

The element does not need to have an id, there are other ways like
getElementsByTagName to find elements.

Cool - thanks Martin.

--
And loving it,

-Q
_________________________________________________
(e-mail address removed)
(Replace the "SixFour" with numbers to email me)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top