4

Well basically I have a website with styles contained within various css files, now I'd like to add a certain js, but only in one style. So I would like to be able to add it in my css file, is such thing possible?

1
  • 2
    Nope, no way. There used to be an Internet Explorer concoction that did something similar but it was phased out in IE8 Commented Jun 24, 2012 at 19:15

2 Answers 2

4

No, this is not possible, and nor should it be. Separate your application logic from your styling.

For when the two need to interact, you can detect certain styles with JavaScript and load various other JavaScript files from there.

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

1 Comment

Pretty much what I expected, I'll just seperate them then.
4

No, this isn't possible. However, look into jQuery selectors to attach JavaScript functionality to certain CSS class names:

http://api.jquery.com/category/selectors/

For example, you could declare an element with a certain class name like this:

<div class="class-name"></div>

And then include some JavaScript in your document which does something to the element based on its class name, like this:

$('.class-name').click(function() {
alert('You clicked .class-name');
});

Here's a jsFiddle example of the above: http://jsfiddle.net/YAZpE/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.