/    Sign up×
Community /Pin to ProfileBookmark

Cloning Styles

Hey everyone,
Is it possible to clone the attributes of a style into another style? I have a label (<label>) in a layer (<div>). I want the label’s style to be identical to the layers style. How can I do this? Oh, and I can’t set the styles in the label directly, only in the layer. And of course, I don’t know which attributes that has been set.

Example:

myLayer.innerHTML = “<label>This is a label</label>”;
myLayer.style.fontSize = 64;

And now I want the fontsize to be 64 in the label as well. It doesn’t seem to inherit the style, so I’ll need to clone it some how. But how?

Thanks on advance,
Nille

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Zach_ElfersJan 13.2003 — You can share styles by using classes. Example:

<style type="text/css">

.className {

attribute: property;

}

</style>

...

Later in the code, when you come to a <div> or <span> which needs this style you do:

<div class="className">
×

Success!

Help @nille40 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 6.13,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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