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?
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With