2
<script>
    $(function(){
        $("a.load").click(function (e) { 
            e.preventDefault();
            $("#main").load($(this).attr("href"));
            // alert("#"+($(this).attr("id")));
            $("."+($(this).attr("class"))).css('border-bottom', 'solid 1px black');
            $("."+($(this).attr("class"))).css('background-color', '#F5F5F5');
            $("#"+($(this).attr("id"))).css('border-bottom', 'solid 2px white');
            $("#"+($(this).attr("id"))).css('background-color', 'white');

        });
    });
</script>

Above function works as expected, despite the fact that :hover properties for one of my class stop working after calling this function. So it seems that jQuery's CSS method is overriding :hover properties. Is there a workaround for this?

I tried adding at the end of the function:

$("."+($(this).attr("class"))+":hover").css('border-bottom', 'solid 2px white');

but it doesn't help.

3
  • Lets see the css with the :hover. Commented May 26, 2013 at 19:50
  • 3
    What's the difference between $("#"+($(this).attr("id"))) and $(this)? Commented May 26, 2013 at 19:51
  • First would return #contact, second: contact. Value of attribute id withouth # at the beginning in CSS would be perceived as an element, not id. Commented May 28, 2013 at 18:52

2 Answers 2

4

I've just discovered !important tag and it did the job! no more overriding!

border-bottom-color: white !important;
border-bottom-width: 2px !important;
background-color: white !important;
Sign up to request clarification or add additional context in comments.

2 Comments

IMHO using !important is not the best way to go about this.
may not be the best way, but works like a charm as a quick fix to make the deadline. thank you!
3

jQuery is not meant to deal with CSS. pseudo-selectors do not exist in the DOM.

Instead, extract your css, and toggle the class with jQuery (addClass/removeClass/toggleClass)

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.