2

I have this in a CSS file:

#tabs .bg {
    background: url("../images/bg-tabs-r.gif") no-repeat scroll 100% 0 transparent;
    height: 39px;
    line-height: 42px;
    overflow: hidden;
    width: 100%;
}

Through JavaScript how do I change background to blank color and line-height to 28px.

2 Answers 2

4

If you use jQuery (you should) it's very easy:

$('#tabs .bg').css({'background': 'none', 'line-height': '28px'});
Sign up to request clarification or add additional context in comments.

4 Comments

jQuery isn't required for this. Just makes the page heavier.
can i call it inside <script type="text/javascript"> </script> ?
Yes, but you have to include the jQuery library first. If you don't want to install jQuery use caffein's answer.
@caffein - I think that depends on how much JS is actually involved and how complicated it's getting. jQuery doesn't actually add very much, especially if you load it from a CDN (increases the chance that the browser will just pick up a cached version), especially if you're using a lot of JS already. That said, if this is the only JS the OP is using, they probably don't need jQuery and it very well could be overkill if vanilla JS works cross browser.
3

Use it directly on your element:

mytab=document.getElementById("tabs");
mytab.style.background="white";
mytab.lineHeight="28px";

4 Comments

This will not remove the bg img.
Why white? Your assuming the element is on a white background?
That was just to put a color in it. Red orange or whatever HTML valid colorname would stand as well.
Tanks for all your help, the two examples work just fine for me :) I cant put the check in the two?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.