javascript - Change Arial to some other font on the whole webpage -


i'm thinking script can change webpage's font appearance arial other font face of choice.

how should go doing that?

i understand: * { font-family: "somefont"; }

but won't achieve objective target arial text.

i can use jquery or javascript, whichever more efficient , fast.

edit: seems people have difficulty understanding question. i'll explain more, want arial text on webpage, if exists, change in appearance.

i going suggest looping through stylesheets array and, each style sheet, loop through rules, find ones defining arial font, , change other font want. way wouldn't have visit every element on page.

the problem suggestion, though, inline styles on elements.

so hate say, you'll have visit every element on page. pages, won't problem, mileage may vary.

here's how you'd jquery:

$("*").each(function() {     var $this = $(this);     if ($this.css("font-family").tolowercase().indexof("arial") !== -1) {         $this.css("font-family", "someotherfont");     } }); 

can't it, though. :-) can avoid building massive list ($("*") builds jquery object containing all of page elements, can quite large) @ outset if recursive walk instead, e.g.:

$(document.body).children().each(updatefont); function updatefont() {     var $this = $(this);     if ($this.css("font-family").tolowercase().indexof("arial") !== -1) {         $this.css("font-family", "someotherfont");     }     $this.children().each(updatefont); } 

that may preferable, you'd have profile it.

doing without jquery involve recursively looping through childnodes of each element , using either getcomputedstyle (most browsers) or currentstyle (ie) font information, (if necessary) assigning element.style.fontfamily.


actually, "both and" solution best. first, update stylesheets, , walk tree catch inline styles. way, presumably you'll of them changing stylesheets, avoid ugliness of piecemeal update. also, don't have use css() (jquery) or getcomputedstyle / currentstyle (without jquery), can check element.style.fontfamily, more efficient.

beware ie's stylesheet object uses array called rules, others use cssrules, other largely same.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -