Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .css() append or overwrite

When appending the .css() function in jQuery 1.4.4 will the .css() override each of the preceding css, or will it append it?

e.g.

$('.GhostIcon').css('opacity', '0.25').css('filter', 'alpha(opacity=25)').css('-khtml-opacity', '0.25').css('-moz-opacity', '0.25');

And secondly, does this have the same behaviour?

$('.GhostIcon').css('opacity', '0.25');
$('.GhostIcon').css('filter', 'alpha(opacity=25)');
$('.GhostIcon').css('-khtml-opacity', '0.25');
$('.GhostIcon').css('-moz-opacity', '0.25');
like image 237
Darbio Avatar asked Dec 06 '10 06:12

Darbio


People also ask

Does jQuery CSS () override each of the preceding CSS?

When appending the .css () function in jQuery 1.4.4 will the .css () override each of the preceding css, or will it append it? And secondly, does this have the same behaviour? Show activity on this post. Setting a CSS property on an element will not remove all the other properties it might already have. So yes, it's cumulative.

How to use CSS in jQuery?

jQuery - css () Method 1 jQuery css () Method. The css () method sets or returns one or more style properties for the selected elements. 2 Return a CSS Property 3 Set a CSS Property 4 Set Multiple CSS Properties 5 jQuery Exercises 6 jQuery CSS Reference. For a complete overview of all jQuery CSS methods, please go to our jQuery HTML/CSS Reference.

How to append content using jQuery and HTML?

append() - Create content with HTML, jQuery and DOM Insert content with the append() method. Append content using a function Using a function to insert content at the end of the selected elements.

What does append () method do in jQuery?

The append () method inserts specified content at the end of the selected elements. Tip: To insert content at the beginning of the selected elements, use the prepend () method.


2 Answers

Setting a CSS property on an element will not remove all the other properties it might already have. So yes, it's cumulative. Of course setting a property that's already set will change the value, since you can't have the same property twice.

Edit: Also, you only need to set opacity. jQuery will take care of setting things for lesser browsers.

like image 81
Matti Virkkunen Avatar answered Sep 20 '22 16:09

Matti Virkkunen


These styles are applied so that it will work cross browser way. Also you can append the CSS in a single go

$('.GhostIcon').css({'opacity': '0.25', 'filter': 'alpha(opacity=25)', '-khtml-opacity': '0.25', '-moz-opacity': '0.25'}); 
like image 25
rahul Avatar answered Sep 24 '22 16:09

rahul