<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>!important css &#8211; Sibeesh Passion</title>
	<atom:link href="https://www.sibeeshpassion.com/tag/important-css/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Tue, 29 Sep 2015 09:01:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>!important css &#8211; Sibeesh Passion</title>
	<link>https://www.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Apply CSS Important In JQuery And CSS</title>
		<link>https://www.sibeeshpassion.com/apply-css-important-in-jquery-and-css/</link>
					<comments>https://www.sibeeshpassion.com/apply-css-important-in-jquery-and-css/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 29 Sep 2015 00:05:33 +0000</pubDate>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[!important css]]></category>
		<category><![CDATA[!important in jquery]]></category>
		<category><![CDATA[Important CSS Property In JQuery And CSS]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=10701</guid>

					<description><![CDATA[In this post we will discuss how we can apply CSS important in JQuery. We all know that we can not apply a important CSS property directly to an element. It does not work. But still there is a solution for that. Here I am going to share you that. I hope you will like this. Background Recently I was going through a situation that to apply a custom CSS to an element which already has some CSS styles and all. I wanted to overwrite those CSS in situation based, that is when some condition satisfies. Using the code First [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this post we will discuss how we can apply <a href="http://sibeeshpassion.com/tag/css/" target="_blank">CSS </a>important in <a href="http://sibeeshpassion.com/tag/JQuery/" target="_blank">JQuery</a>. We all know that we can not apply a important CSS property directly to an element. It does not work. But still there is a solution for that. Here I am going to share you that. I hope you will like this. </p>
<p><strong>Background</strong></p>
<p>Recently I was going through a situation that to apply a custom CSS to an element which already has some CSS styles and all. I wanted to overwrite those CSS in situation based, that is when some condition satisfies.</p>
<p><strong>Using the code</strong></p>
<p>First of all we will create a page and some div element.</p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;CSS Important In JQuery&lt;/title&gt;<br />
    &lt;script src=&quot;jquery-2.0.2.min.js&quot;&gt;&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
    &lt;div id=&quot;container&quot;&gt;<br />
        &lt;div style=&quot;width: 25px;height: 28px;padding: 5px;background-color: green;margin: 3px;float: left;cursor: move;&quot; &gt;&lt;/div&gt;<br />
        &lt;div style=&quot;width: 25px;height: 28px;padding: 5px;background-color: green;margin: 3px;float: left;cursor: move;&quot; &gt;&lt;/div&gt;<br />
        &lt;div style=&quot;width: 25px;height: 28px;padding: 5px;background-color: green;margin: 3px;float: left;cursor: move;&quot; &gt;&lt;/div&gt;<br />
    &lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>[/html]</p>
<p>You an see that I have loaded a JQuery reference and added some in-line CSS to the elements. As you all know, even if we give a custom css as follows</p>
<p>[css]<br />
 &lt;style&gt;<br />
        #container div {<br />
            width:55px;<br />
        }<br />
    &lt;/style&gt;<br />
[/css]</p>
<p>The width will be 25px, because we have set the in-line css as </p>
<p>[html]<br />
&lt;div style=&quot;width: 25px;height: 28px;padding: 5px;background-color: green;margin: 3px;float: left;cursor: move;&quot; &gt;&lt;/div&gt;<br />
[/html]</p>
<p>Now if you run your page and, check your browser console you can get to know that.</p>
<div id="attachment_10702" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_1.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-10702" src="http://sibeeshpassion.com/wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_1-1024x146.png" alt="Important CSS Property In JQuery And CSS" width="634" height="90" class="size-large wp-image-10702" srcset="/wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_1-1024x146.png 1024w, /wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_1-300x43.png 300w, /wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_1-768x110.png 768w, /wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_1-400x57.png 400w, /wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_1.png 634w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-10702" class="wp-caption-text">Important CSS Property In JQuery And CSS</p></div>
<p>In this situation, we use !important tag in the css, So if you change your css styles as follows, you can see your new css is getting applied. </p>
<p>[css]<br />
&lt;style&gt;<br />
        #container div {<br />
            width:55px !important;<br />
        }<br />
    &lt;/style&gt;<br />
[/css]</p>
<p>Now refresh your page and see the browser console. </p>
<div id="attachment_10703" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_2.png"><img decoding="async" aria-describedby="caption-attachment-10703" src="http://sibeeshpassion.com/wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_2-1024x145.png" alt="Important CSS Property In JQuery And CSS" width="634" height="90" class="size-large wp-image-10703" srcset="/wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_2-1024x145.png 1024w, /wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_2-300x42.png 300w, /wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_2-768x109.png 768w, /wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_2-400x57.png 400w, /wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_2.png 634w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-10703" class="wp-caption-text">Important CSS Property In JQuery And CSS</p></div>
<p>Now what if you need to change this CSS, when there is a jquery action. For example you need to change the css styles when user clicks on an element? Cool, we have a solution for that too. Now you will be thinking the solution is as follows. </p>
<p>[js]<br />
 &lt;script&gt;<br />
        $(function () {<br />
            $(&#8216;#click&#8217;).click(function () {<br />
                $(&quot;#container div&quot;).css(&#8216;width&#8217;, &#8217;75px;!important&#8217;);<br />
            });<br />
        });<br />
    &lt;/script&gt;<br />
[/js]</p>
<p>Here #click is my a href.</p>
<p>[html]<br />
&lt;a href=&quot;#&quot; id=&quot;click&quot;&gt;Click&lt;/a&gt;<br />
[/html]</p>
<p>If you run that, you will know it didn&#8217;t work. No worries, I am going to share you a solution for this. </p>
<p>Now we will change our script as follows.</p>
<p>[js]<br />
 &lt;script&gt;<br />
        $(function () {<br />
            $(&#8216;#click&#8217;).click(function () {<br />
                //$(&quot;#container div&quot;).css(&#8216;width&#8217;, &#8217;75px;!important&#8217;);<br />
                $(&quot;#container div&quot;).each(function () {<br />
                    this.style.setProperty(&#8216;width&#8217;, &#8217;75px&#8217;, &#8216;important&#8217;);<br />
                });<br />
            });<br />
        });<br />
    &lt;/script&gt;<br />
[/js]</p>
<p>And it is tie to run our page now. </p>
<div id="attachment_10704" style="width: 343px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_3.png"><img decoding="async" aria-describedby="caption-attachment-10704" src="http://sibeeshpassion.com/wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_3.png" alt="Important CSS Property In JQuery And CSS" width="333" height="58" class="size-full wp-image-10704" srcset="/wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_3.png 333w, /wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_3-300x52.png 300w, /wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_3-330x58.png 330w" sizes="(max-width: 333px) 100vw, 333px" /></a><p id="caption-attachment-10704" class="wp-caption-text">Important CSS Property In JQuery And CSS</p></div>
<p>Just click on the href, and see the output and browser console.</p>
<div id="attachment_10705" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_4.png"><img decoding="async" aria-describedby="caption-attachment-10705" src="http://sibeeshpassion.com/wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_4-1024x476.png" alt="Important CSS Property In JQuery And CSS" width="634" height="295" class="size-large wp-image-10705" srcset="/wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_4-1024x476.png 1024w, /wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_4-300x139.png 300w, /wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_4-768x357.png 768w, /wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_4-400x186.png 400w, /wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_4-1292x600.png 1292w, /wp-content/uploads/2015/09/Apply_CSS_Important_In_JQuery_And_CSS_4.png 1901w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-10705" class="wp-caption-text">Important CSS Property In JQuery And CSS</p></div>
<p>We have done it finally.</p>
<p><strong>Complete Code</strong></p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;CSS Important In JQuery&lt;/title&gt;<br />
    &lt;script src=&quot;jquery-2.0.2.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;script&gt;<br />
        $(function () {<br />
            $(&#8216;#click&#8217;).click(function () {<br />
                //$(&quot;#container div&quot;).css(&#8216;width&#8217;, &#8217;75px;!important&#8217;);<br />
                $(&quot;#container div&quot;).each(function () {<br />
                    this.style.setProperty(&#8216;width&#8217;, &#8217;75px&#8217;, &#8216;important&#8217;);<br />
                });<br />
            });<br />
        });<br />
    &lt;/script&gt;<br />
    &lt;style&gt;<br />
        #container div {<br />
            width:55px !important;<br />
        }<br />
    &lt;/style&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
    &lt;div id=&quot;container&quot;&gt;<br />
        &lt;div style=&quot;width: 25px;height: 28px;padding: 5px;background-color: green;margin: 3px;float: left;cursor: move;&quot; &gt;&lt;/div&gt;<br />
        &lt;div style=&quot;width: 25px;height: 28px;padding: 5px;background-color: green;margin: 3px;float: left;cursor: move;&quot; &gt;&lt;/div&gt;<br />
        &lt;div style=&quot;width: 25px;height: 28px;padding: 5px;background-color: green;margin: 3px;float: left;cursor: move;&quot; &gt;&lt;/div&gt;<br />
    &lt;/div&gt;<br />
    &lt;a href=&quot;#&quot; id=&quot;click&quot;&gt;Click&lt;/a&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>[/html]</p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed?Have you ever faced this issue in your programming life? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I am able to.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/apply-css-important-in-jquery-and-css/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
