473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can JS place html code into a DIV ????

Hi,

What I like to know is if it is possible to have a JavaScript writing code
into a DIV section, that is say during load or on a certain event in the
same page it would insert the word "hello"

----------------
.......
<script>
function insert_hello(){
?????
}
</script>

<body onload="insert_hello()"....

<div id=div1 name=div1>

</div>
....

-----------------

...so it would display the word "hello" in the area taken up by the <DIV
id=div1 name=div1>
I understand you can change attributes/properties like the value of a text
field but what about this scenario???
TIA,

Tom

Jul 23 '05 #1
4 930
Tom Szabo wrote:
Hi,

What I like to know is if it is possible to have a JavaScript writing code
into a DIV section, that is say during load or on a certain event in the
same page it would insert the word "hello"

----------------
......
<script>
function insert_hello(){
?????
}
</script>

<body onload="insert_hello()"....

<div id=div1 name=div1>

</div>
...

-----------------


You may use innerHTML which isn't a W3 standard but is supported by
nearly all browsers out there:

function insert_hello(){
var yourElm = document.getElementById("div1");
if (yourElm)
yourElm.innerHTML = "Hello<br>everybody";
}

Daniel
Jul 23 '05 #2
thanks, working well!
"Daniel Kirsch" <Iw*****************@gmx.de> wrote in message
news:cn*************@news.t-online.com...
Tom Szabo wrote:
Hi,

What I like to know is if it is possible to have a JavaScript writing code into a DIV section, that is say during load or on a certain event in the
same page it would insert the word "hello"

----------------
......
<script>
function insert_hello(){
?????
}
</script>

<body onload="insert_hello()"....

<div id=div1 name=div1>

</div>
...

-----------------


You may use innerHTML which isn't a W3 standard but is supported by
nearly all browsers out there:

function insert_hello(){
var yourElm = document.getElementById("div1");
if (yourElm)
yourElm.innerHTML = "Hello<br>everybody";
}

Daniel

Jul 23 '05 #3
"Tom Szabo" <to*@intersoft.net.au> wrote in message news:<41******@dnews.tpgi.com.au>...
Hi,

What I like to know is if it is possible to have a JavaScript writing code
into a DIV section, that is say during load or on a certain event in the
same page it would insert the word "hello"

----------------
......
<script>
function insert_hello(){
?????
}
</script>

<body onload="insert_hello()"....

<div id=div1 name=div1>

</div>
...

-----------------

..so it would display the word "hello" in the area taken up by the <DIV
id=div1 name=div1>
I understand you can change attributes/properties like the value of a text
field but what about this scenario???
TIA,

Tom


Read all about it:

http://www.scottandrew.com/weblog/articles/dom_1
Jul 23 '05 #4
Hello

You surely can.

There are two ways to do this.

Firstly use the innerHTML property (supported by IE and Mozilla) which
takes HTML mark up as a string.

document.getElementById("div1").innerHTML="<P>Hell o</P>";

Alternatively use DOM methods:-

var eP=document.createElement("P");
var eT=document.createTextNode("Hello");
eP.appendChild(eT);
document.getElementById("div1").appendChild(eP);

Julian
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: success_ny | last post by:
I would like to be able to display either one or the other HTML table in the same place. I.e., there are 2 buttons on the screen. When the user clicks one button, the table A is displayed below....
3
by: vitaly.tomilov | last post by:
I'm using an ASP.NET form to display data from my database table, and I'm doing it in the following way: XmlDataDocument doc = new XmlDataDocument(mydataSet); XPathNavigator nav =...
2
by: J-T | last post by:
I am constructing an HTML text which I need to render in my ASP.NET page. string rssOutput = Posts.listPosts(Constants.WeblogSectionID); rssOutput contains html code and text.Then I create a...
10
by: Iain | last post by:
Hi All My apologies if this appears to be simple to some of you but I have very little experience of javascript and I cannot work this one out, The code below is a nice piece of code I found...
5
by: acord | last post by:
Hi, I m getting annoying display problem when placing javascript tags in a html page. Should the javasscript tags placed at the beginning of a html page before anything start? or placed between...
5
by: Ian Bicking | last post by:
I got a puzzler for y'all. I want to allow the editing of functions in-place. I won't go into the reason (it's for HTConsole -- http://blog.ianbicking.org/introducing-htconsole.html), except that...
1
by: lamuerte451 | last post by:
Hi: I am a newbie to asp.net 2.0 and am building an app with VS 2005 that will allow users to update records via the web. I have created a master page and then have placed Gridview and details...
22
by: pamelafluente | last post by:
Dears, I'd like to know the cleanest solution for the following problem. I want to insert some CSS/htm after a long vertical column of DIVs absolutely positioned. Since this code is generated...
10
by: mark4asp | last post by:
I ask this because only today I read advice telling me to put it within the <headelement. This is the same advice I've always been given but no one ever explained why. Last week I was told to...
2
by: Reggie | last post by:
Hi and TIA! I have a class file located in my root directory with all me web pages. I call/use the class and it works fine. I have no imports statements aspx or codebehind. My question is why? ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.