WhatisSober
WhatisSober

Reputation: 988

Escaping hyphen on javascript's getElementbyId

I want to pass -webkit-background-clip property with javascript.

Because of the hyphen at start, I cant seem to get it right. Tried it with [, ", ' etc. How do I escape dash?

document.getElementById("menu").style.-webkit-background-clip = "text";

Upvotes: 0

Views: 1633

Answers (2)

alex
alex

Reputation: 490263

You can use bracket notation...

document.getElementById("menu").style["-webkit-background-clip"]

...or use camel case...

document.getElementById("menu").style.webkitBackgroundClip 

jsFiddle.

Note that JavaScript resolves these to different names, but the browser supports both.

Upvotes: 3

OpherV
OpherV

Reputation: 6937

try document.getElementById("menu").style["-webkit-background-clip"] = "text";

Upvotes: 1

Related Questions