PDA

View Full Version : Howto: DIV as object???


SIGINT
08-28-2002, 11:29 AM
Hi everybody,
i want to build an class for handling DIV's as object (modify their properties with methods and different eventhandlers for different instances).My problem is,how do i create the DIV with the constructor and modify it with some methods?? I've looked everywhere but didn't find the solution...

Thx SIGINT

P.S.: I'm new to JavaScript,so sorry for this dumb question...:rolleyes:

zuckera
08-28-2002, 11:41 AM
Hi,

In my response in this thread (http://www.codingforums.com/showthread.php?s=&threadid=4947) I attach an object to a text field which handles events. This should be easy enough to use with divs.

hth,

Amir

jkd
08-28-2002, 12:07 PM
Create a DIV:

var div = document.createElement('div');

You can modify its attributes with the setAttribute('attName', 'attValue') method, and add it to the document by:
document.body.appendChild(div) (among other ways).

SIGINT
08-28-2002, 12:45 PM
Hey cool, this was fast...

Thx everybody,i'll try this.Javascript and OOP is great. :)

SIGINT

Vladdy
08-28-2002, 01:04 PM
FYI:

divobject.setAttribute('class','divstyle')

would not produce the expected result in stoopid IE. Use

divobject.className='divstyle'