How to add css class to style.css?


Tags: jquery,css

Problem :

I have this code by helping of skobaljic which add title to class in div

$(document).on('ready', function() {
	$("[title*='animotion']").addClass(function(){
		$(this).parent().css('overflow','visible');	
		return $(this).attr('title');
	}).removeAttr('title');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<p><img src="http://placehold.it/350x150" title="animotion newClass new1" /></p>

How to add these new classes to style.css with jQuery?



Solution :

The short answer is - you don't do it that way.

Define the styles in the css file, then use the classes in the html - whether added inline or manipulated by jQuery - to attach the css rules to your html elements. Your css file doesn't change while in use. Your html document might change based on what javascript is being applied to it but the source file remains unchanged.


    CSS Howto..

    How to edit a div inside PHP using CSS

    How to remove the input field around an image button?

    How to load an image with css using Django

    How do I apply CSS style to ASCII character

    How to solve placeholder CSS difference across different browsers?

    How can I get facing html elements to left-align and right-align, respectively, preferably using CSS?

    How do you style Wordpress sub-menus with CSS?

    How to position AdSense on site with CSS position: absolute

    CSS / Javascript: hidden div does not take full width after being shown

    How to reload CSS after ajax call

    How to set a div within text?

    Jquery datepicker only year and month how to set CSS to hide calendar when there are severals datepickers?

    CSS: How to shorter code having select direct children with multiple id

    How to add a Delay on Bootstrap Dropdown Hover

    How to set a max-width only to text nodes not in a tag?

    How to center my hmenu (no matter the resolution)?

    How can I make a pointy arrow with a div in CSS

    How to create an ActionImage from a CSS Sprite

    How to create square image thumbnails using only CSS

    How to push down second dropdown when open first ?

    how to change text color hover

    How to create 3d ribbon box in css

    specifiy UL properties for nested class (sociallinks) but still it is working as a property of parent class (header) how can i solve it?

    How to create a 1px height div in IE8

    How do you make linked text act as if it is normal text?

    CSS + Bootstrap: How to dynamically stretch subdiv width to fit container (with image)?

    How to scrape a live java script webpage in R?

    how to give style to the selected option in html

    How to toggle display: inline and display toggle?

    How to access CSS children properly?