/    Sign up×
Community /Pin to ProfileBookmark

Adding a class property dynamically

Greetings,

I am trying to create new layers on the fly and give them a class property so that they can be draggable. For some reason they are not able to use the drab property even though I am giving them the class drag attribute. Here is the function that I use to add the new div layer. Drag is the name of the class that I want the new layers to use, it is also a javascript function.

function clickSchedule(id,L,T,W,H,bgColor,visible,zIndex) {
if (document.layers) {
if (document.layers[id]) {
alert (‘Layer with this ID already exists!’)
return
}
x=event.clientX
var LR=document.layers[id]=new Layer(W)
LR.name= id
LR.left= event.clientX
LR.top = T
LR.clip.height=H
LR.className = drag
LR.visibility=(null==visible || 1==visible ? ‘show’ : ‘hide’)

if(null!=zIndex) LR.zIndex=zIndex
if(null!=bgColor) LR.bgColor=bgColor
}
else if (document.all) {
if (document.all[id]) {
alert (‘Layer with this ID already exists!’)
return
}
var LR= ‘n<DIV id=’+id+’ style=”position:absolute’
+’; left:’ +event.clientX
+’; top:’+T
+’; width:’+W
+’; height:’+H
+’; clip:rect(0,’+W+’,’+H+’,0)’
+’; class: drag ‘
+’; border: #000000 2px solid’
+’; visibility:’+(null==visible || 1==visible ? ‘visible’:’hidden’)
+(null==zIndex ? ” : ‘; z-index:’+zIndex)
+(null==bgColor ? ” : ‘; background-color:’+bgColor)

+'”></DIV>’

document.body.insertAdjacentHTML(“BeforeEnd”,LR)
}
}

Any ideas on what I am doing wrong? I am completely new to javascript coming from oo programming languages.

Thanks,
Kevin

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangSep 07.2005 — [I]class[/I] is not an attribute of [I]style[/I], it is an element attribute.

Read up on the [URL=http://www.brainjar.com/dhtml/intro/]DOM[/URL]
×

Success!

Help @kevinmtu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...