views:

220

answers:

5

I have one CSS style sheet with rules like this:

h1, h2, h3, h4, .contentheading, .title{

 font-size: 13px ;
 font-weight: normal;
 font-family: Arial, Geneva, Helvetica, sans-serif ;
}

The tags, classes are generated by plugin so i can't add a single class to it.

So, is there any way that I can change the styles of all elements at once, at runtime, that doesn't involve going through them one by one?

+4  A: 

You can do multiple selectors in jQuery just like in Css. Maybe not the best performance-wise but will work.

$('h1, h2, h3, h4, .contentheading, .title').css('color', 'red');
$('h1, h2, h3, h4, .contentheading, .title').addClass('someOtherClass');
redsquare
Instead of doing the lookup twice, it would perform better to chain your method calls: `$('h1...').css('color', 'red').addClass('someOtherClass');`
Joel Mueller
it was an example to show thats how to apply css to all those elements or to apply a class.....
redsquare
A: 

In CSS:

* {
    font-size: 13px;
    font-weight: normal;
    font-family: Arial, Geneva, Helvetica, sans-serif;
}
John Keyes
Is there any way where i can get the current font-size of all elements and then increase by one
Mirage
Yes. Just iterate over each element. Two problems though. It can be expensive if the DOM is big, and the size does not have to be a px, it could be a pt, em or % too. That makes your job that bit harder. Why would you want to do this in JavaScript anyway?
John Keyes
A: 
$('h1,h2,h3,h4,.contentheading,.title').css({ 'color': '#fff' });
Stuart Branham
A: 

Since this question is tagged jQuery, using the * selector should help you to get all elements. Then you can use the css method to change the styles.

$('*').css();

In CSS you can just use the same * selector to apply some styles to all elements, but make sure you put it last of the CSS file so as to override all other rules.

* {
    font-size: 13px;
    font-weight: normal;
    font-family: Arial, Geneva, Helvetica, sans-serif;
}
thephpdeveloper
A: 

This is very simple with jQuery. Simply use the selectors in question as your jQuery selectors, then change the css. So the JavaScript/jQuery code would be this, assuming you wanted to change the font-size and font-weight:

$('h1, h2, h3, h4, .contentheading, .title').css({
  'font-size': '17px',
  'font-weight': 'bold'
});

It sounds like you're new to jQuery, you probably want to get familiar with the docs and api sites.

artlung