0

I have styled my css like this

.mycss{border: 2px solid; background: url("") no-repeat;}

how could I add #f00 right after solid and right after no-repeat with a space with jquery?

Edit What if I would like to edit my css with js?

4
  • Where is your CSS? In the document itself or in a stylesheet? And why are you parsing/adapting your styles with JavaScript/jQuery? Commented Jul 7, 2013 at 10:26
  • I would like to do it once. Commented Jul 7, 2013 at 10:37
  • What if I would like to edit my css with js? Commented Jul 7, 2013 at 10:41
  • then you can add a style tag with jquery for examlpe: $('head').append(<style type=..>your css goes here</style> Commented Jul 7, 2013 at 10:46

3 Answers 3

1

You can simply use this:

.mycss:hover{border: #f00; background-color: #f00;}

and it will do what you want you can add it rightin your css or your html page as a style tag there is no need to use js or jq for this, and it will add them to this css because you are adding something not editting :D

Sign up to request clarification or add additional context in comments.

2 Comments

background: #f00; will override the image.
then you can be more specific: background-color: #f00;
0

Use specific CSS properties for color:

background-color: #f00

That will not override background-image or background-position. For border there is border-color property.

Comments

0

As others mentioned, css is the way to go. But, if you still want to use jQuery, here's a way you could do this.

  • Add a class with the styles you want to add when hovering.

    .onHover {
        border-color: #f00;
        background-color : #f00
     }
    
  • Then you could use the hover event of jQuery and toggle the class whenever hovering.

     $(".mycss").hover(function () {
       $(this).toggleClass("onHover");
     });
    

Demo : http://jsfiddle.net/hungerpain/gU7Zp/

Comments

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.