3

I'm trying to change jQuery dialog's font-family from a little display settings panel. I've tried all of these to no avail:

$('#orderHolder').style.fontFamily='Bookman Old Style';
$('.ui-dialog-content').style.fontFamily='Bookman Old Style';
$('.ui-widget-content').style.fontFamily='Bookman Old Style';
$('#orderHolder').css("font-family", "Bookman Old Style';
$('*').css('font-family', 'Bookman Old Style'); //this is what I'm after 

(#orderHolder being the div that contains the dialog content)

I found
*{ font-family: 'Bookman Old Style'; }

in the .css file works fine, and the overall effect is what I am after.

So, How do you select all elements for styling in javascript?

1
  • I have tried document.body.style however this does not replicate to the dialog. I assume due to jqeury's imported ui css Commented Aug 14, 2014 at 10:23

5 Answers 5

10

jQuery:

$('*').css('font-family','Bookman Old Style');

javascript:

document.querySelectorAll('*').style.fontFamily = 'Bookman Old Style';

Update:

Actually you need to iterate over all element when you use querySelectorAll:

var el = document.querySelectorAll('*');
for(var i=0;i<el.length;i++){
  el[i].style.fontFamily = 'Bookman Old Style';
}

But this is unnecessary to iterate over all element while using asterisks selector, you can just use querySelector:

document.querySelector('*').style.fontFamily='Bookman Old Style';

But actually if you set font-family to the body your font will be inherited to all element, so rather than other thing just apply to the body.

Sign up to request clarification or add additional context in comments.

2 Comments

As this answer was first with all other answers pointing to the same direction, i'll just comment here. I've had no success with any of the answers given. I'm sure that somewhere along the timeline, jquery ui css is blocking my functions from working correctly ( or at least applying the style). am continuing with trial & error
yesterday I was gone after posting my answer and didn't answer the full coz of network problem, so sorry for that, anyway check my update please.
3

You may need to make it as important style: Also if any other font-family is there then please remove it. try the below code

In CSS:

*{
font-family: 'Bookman Old Style' !important;
}

In jquery:

$('#content').find('*').css("font-family","'Bookman Old Style'");

4 Comments

does #content refer to my #orderHolder where the .dialog is called?
you can add elements id there instead of content.
this isn't just "JS"
you solved my issue: $('.content').find('a,img,button').attr('tabindex','0');
2

I found

*{
   font-family: 'Bookman Old Style';
}

in the .css file works fine, and the overall effect is what I am after.

In that case, since you apparently aren't applying font-family to more specific selectors, your best bet is to add a style element to the document with that rule:

$("<style>* { font-family: 'Bookman Old Style'; }</style>").appendTo("head");

Or possibly:

$("<style>body { font-family: 'Bookman Old Style'; }</style>").appendTo("head");

...if they all inherit their style from body.

That way, it applies throughout, and also to new elements you add afterward.

3 Comments

I don't think document.body in the style tag is what you want--did you mean "<style>body { font-family:...}</style>"?
@TurnerHayes: Thank you. I wonder how tired I was when I wrote that. :-)
Doing this with pure JavaScript: stackoverflow.com/questions/524696/…
0

None of the previous answers worked for me. But this:

document.head.innerHTML = document.head.innerHTML + '<style type="text/css">*{font-family: Georgia !important }</style>'

Comments

-1

**Apply following methods **


1.jQuery $('*').css('fontFamily','Times New Roman');

2.Java script document.querySelectorAll('*').style.fontFamily = 'Times New Roman';

3.Css *{ font-family: 'Times New Roman'; }

1 Comment

Most Commonly you use *{ font-family: 'Times New Roman'; } in style

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.