0

I'm trying to get some css with jquery in internet explorer.

The css is set in a external file and looks like this:

#something a {
    text-decoration: none;
    /* since I dont want underline when not hover */
}

#something a:hover {
    text-decoration: underline;
}

And I want to get if underline is set or not.

This works in firefox and webkit but not IE:

$('a').hover(function() {
    console.log($(this).css('textDecoration'));
    /* this return underline in FF and Webkit but not in IE */
});

Does anyone know how to get it to work in IE?

15
  • @Patrik Hi friend, your code return the correct property i checked in IE7+. which version of IE you are using?Here one think to note that <a> tag by default possess underline. so if you dont give any text-decoration to it using css, moreover the code will return underline Commented May 31, 2011 at 11:21
  • @abdullah.abcoder Hm... are you sure you tried with :hover? try set #something a { text-decoration: none; } and #something a:hover { text-decoration: underline; } || I will update my example code a bit. Commented May 31, 2011 at 11:29
  • You question is illogical. Inside the hover event the link will always be underlined, so it's no point in testing if it is. Is your example correct? Do you actually need to know if the link is underlined, or if it's only being hovered? Commented May 31, 2011 at 11:37
  • @RoToRa I want to know if the element i'm hovering is supposed to have an underline or not. Commented May 31, 2011 at 11:42
  • 1
    Ok, the goal of my questions was to see if there were any alternatives to detecting the underline, but now I know your goal, see there doesn't seem to be. Let me think about it for a bit... Commented May 31, 2011 at 12:12

4 Answers 4

1

Adding a setTimeout makes it work:

$("a").hover(function() {
    var x = $(this);
    setTimeout(function() {
      console.log(x.css("text-decoration"));
    }, 1);
});

http://jsfiddle.net/ZGKqC/2/

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

1 Comment

Thanks it's working but the hover function is failing. Mouse over works but mouse out doesnt work (same code works in ff/webkit) jsfiddle.net/SeaNC
0

try like this...

$('a').hover(function() {
    $(this).css('text-decoration','underline');
});

2 Comments

Why the negative vote? +1 for the same reason the -1 was originally placed.
-1 was for not being even close. The OP doesn't want to set underline, he want's to know if it's set.
0

Try this Bro:

$('a').css('textDecoration', 'none'); //initially set no underline 
$('a').mouseenter(function() {
    $(this).css('textDecoration', 'underline'); //set underline in hover in
}).mouseleave(function() {
    $(this).css('textDecoration', 'none'); // set no underline in hover out
});

4 Comments

@Patrik this code independent form css property i.e. if underline is set or not to a
-1 for not being even close. The OP doesn't want to set underline, he want's to know if it's set.
The problem is that I don't know if the link should have underline. If i write a:hover { text-decoration: underline } I want the js to check the css and say "this link should have underline" and if I write text-decoration: none; it should say "This link should not be underlined".
@RoToRa it was my lack to understand OP's view.In future try to avoid this error.Thanks again.
0

Try following

$('a').hover(function() {
     console.log($(this).css('text-decoration'));         
});

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.