0

I have a div I'm displaying a button image on. I'm displaying a sprite actually. I'd added an onlick attribute to the tag and it calls a function called ACFunction. I know how to set the style attribute with css properties using javascript but I need to set the style attribute with each one of these properties below except I will set them to have different values slightly and those values will allow for the image I want to be displayed when the button is clicked, to show up.

so right now, this is the current inline style for the button

style="width:74px; height:99px; background:url(images/icons.png) -0px -0px;"

Can I use:

 document.getElementById('id').style.

for each one of those properties? How would I set the background:url one?

2
  • 1
    $("#id").css({"width":"74px", "height":"99px","background":"url(images/icons.png) -0px -0px"}); Commented Oct 17, 2013 at 4:21
  • Or without jQuery: document.getElementById(id).style.cssText = 'width:74px; height:99px; background:url(images/icons.png) -0px -0px;'. Commented Oct 17, 2013 at 4:38

5 Answers 5

3

jQuery

$("#id").css({"width":"74px", "height":"99px",
              "background":"url(images/icons.png) -0px -0px"});
Sign up to request clarification or add additional context in comments.

Comments

3

yes you can use

document.getElementById('id').style.property = value;

also like this

    document.getElementById("demo").setAttribute(
   "style", "font-size: 100px; font-style: italic; color:#ff0000;");

even this

document.getElementById("myElement").style.cssText = cssString; 

Css String

in jquery

$("#idname" or ".classname").css("property":"value");

Comments

0

in jquery

for single attribute setting

$("#idname").css("background":"desired setting");// for background setting

for multiple attribute

$("#idname").css({"width":"74px",
                  "height":"99px",
                   "background":"url(images/icons.png) -0px -0px"
                  });

reference css

Comments

0

Yes you can use document.getElementById('id').style.
use background attribute like background: url('');

Comments

0

Try this :

* Define all styles with the classname "myStyles".

* $("#id").addClass("myStyles");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.