1

External CSS file...

#externalClass { font-family: arial; }

HTML file...

<a href="#" id="externalClass">Link</a>

JavaScript file...

console.log(jQuery("#externalClass").css("font-family"));

I get the "arial", but not able to understand how it's working (even in IE6/7/8/9) in native javascript?

Can someone explain it please.

2
  • 2
    Have you looked at the jQuery source code? Commented Sep 21, 2012 at 7:05
  • 1
    Read the documentation: api.jquery.com/css Commented Sep 21, 2012 at 7:05

2 Answers 2

2

It uses getComputedStyle() (with necessary fallbacks such as currentStyle()) to calculate the font-family value.

Source.

When you're wondering how a library achieves something, the best way is to look at the source, and if you're stuck comprehending it, then Google more or ask here :)

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

Comments

0

There is exists style property for DOM element, where you can get or set needed CSS styles. In your case - document.getElementById("externalClass").style.fontFamily

1 Comment

yes it's work while set CSS property to DOM, but what if need to know, what CSS already applied?

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.