[Javascript] netscape: how to write to <div> tag??

BEKIM BACAJ Trojani2000 at hotmail.com
Wed Jun 27 00:37:00 CDT 2001


Sure!

In IE you can use any element to write inside of it.

<div ID="newContent" style="color:red">The old text otherwise left empty?!<br></div>

If you like to have it positioned and formated as previously defined you do it in you're  
<style>
</style>
element.

If only this element uses this format refer it from it's ID like this:
#newContent{position:absolute/relative
                    Top:
                    Left:
                    Font:
                    Background:
                    color:
                    ...etc...
                    }
If the DIV is empty
     Try using:  
                newContent.innerText="the fool content";
...through JavaScript function.
If the div is not empty and you like to add the new content without wiping the current
     Try using:  
                newContent.insertAdjacentText('AfterBegin/BeforeEnd', 'the content' )
Depending on wether you like the new content to apear after or before the older text you will chose AfterBegin or BeforeEnd, sametime preserving the formating you've specifyed in you're CSS.

Otherwise [!more control], If you like to add a new content even a newer tag and separate content with different formating attributes
      Try using:
                newContent.insertAdjacentHTML('AfterBegin/BeforeEnd', '<the tag and the style attributes>the content</the tag>' )  
or if you like to have completely new content element f.i. div,p,span, etc; rendered relative to the desired element before or after it (that is:outside)
      Try using:  
                newContent.insertAdjacentHTML('BeforeBegin/AfterEnd', '<the tag and the style attributes>the content</the tag>')
* You can also use the ID or Class assignment to refer through the CSS formating in the style section instead the inlined style definition
And now the function
                function freshContent(){
                                   theContent="simply inserted newer text over the older one or if empty tag filling it with content"
                                   theContent1=" inserted newer text over the older one <i>made italic.</i>"
//or if you like to have some extra formating inside the new text like underlined or bold even italic
                                  theContent2="<br>This will be wrtitten formating this<b> bold</b> just before the old text<br>"
//but in case you like to have an extra tag that is only dependent in preceeding order, than you would do something like this:
                                  theContent3="<div id=before><u>This tag apears before the referencial tag underlined</u></div>"
//please format this new tags inside <style></style> part of document, -worthed for redability and flexibile control of it's future style changes
                                  theContent4="<br>This will be wrtitten formating this<b> bold</b> behind the old text"
                                  theContent5="<div id=after><i>This tag apears after the referencial tag in italic</i></div>"
//*********************************************************************************************************
                                 newContent.innerText=theContent
                                 newContent.innerHTML=theContent1+"(The  replaced text).<br>"
                                 newContent.insertAdjacentHTML('AfterBegin', theContent2+"<BR>")
                                 newContent.insertAdjacentHTML('BeforeBegin', theContent3)
                                 newContent.insertAdjacentHTML('BeforeEnd', theContent4+" <br>")
                                 newContent.insertAdjacentHTML('AfterEnd', theContent4)
                                }
//insert comment signs before the first and second statement if you like to preserve the old text of the tag
// when you're done, use any kind of event onclick onmouseover etc to execute it
PRECAUTION: CREATE SOME SCRIPT HANDLER FOR THE INSERTADJACENT BECAUSE IT EXECUTES E NEW LINE/TAG EVERY TIME YOU CALL THE FUNCTION, TRY USING ENABLE/DISABLE FOR BUTTONS


Cheers




----- Original Message -----
From: Andrew Dunn
Sent: Wednesday, June 27, 2001 4:21 AM
To: javascript at LaTech.edu
Subject: RE: [Javascript] netscape: how to write to  
tag??


Hi,
   is it possible to write stuff to parts of a page (like the div tag) after
the page has loaded without causing the rest of the page to clear?

Andrew

-----Original Message-----
From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
Behalf Of Andrew Gibson
Sent: Wednesday, 27 June 2001 7:43 AM
To: javascript at LaTech.edu
Subject: RE: [Javascript] netscape: how to write to <div> tag??


from memory I think you need to go

document.layers["div1"].document.write("hello")
document.close()

Andrew Gibson

> I can write to <div id="div1"> in IE4, but not in
> Netscape 4.7
>
> I've tried the following without any success...please
> help to write to NS 4 <div> ('layers'):
>
> =========
>
>
>   <script language="JavaScript">
>   <!--
>   function layer() {
>     if (!document.all) {
>       document.layers["div1"].document.write("hello
> NS");
>     } else if (document.all) {
>       document.all["div1"].innerHTML = "Hello IE";
>     }
>
>   }
>
>   // -->
>   </script>
>
> =========
>
> <a href="javascript:layer();">Click</a><br>
>
> <div id="div1">
> div 1 layer
> </div>
>
> =========
>
> =====
> --
> Anthony E.
> AP Web Design
>
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> http://www.LaTech.edu/mailman/listinfo/javascript
>

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
http://www.LaTech.edu/mailman/listinfo/javascript


_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
http://www.LaTech.edu/mailman/listinfo/javascript<br clear=all><hr>Get Your Private, Free E-mail from MSN Hotmail at <a href="http://www.hotmail.com">http://www.hotmail.com</a>.<br></p>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20010627/21443606/attachment.htm>


More information about the Javascript mailing list