Anyone knows how to put all of the elements on the开发者_运维百科 page into array?
I want to loop throug all of them and increase the font size relatively to the currently set one.
Thanks
First, you can do this with the universal selector $('*')
. However, do not do this. Whatever you are trying to do, this is the wrong way to do it.
You should do this by setting all your fonts to be relative to a base size (using percentages or em
s) and changing the global (body
) font-size. That would have far, far better performance.
Maybe it is like this.
$('*');
Sorry to rack up this oldie, but I was searching for a solution and I have found it.
I hope others might still find this usefull:
- Make sure your font-sizes are expressed as % or em
code:
<script type="text/javascript">
//currentsize is the percentage of all elements within the body or container
var currentsize = 100;
//function when a button is clicked orso
function sizeIncrease(){
//increase the percentage of fontsize by 10
currentsize = currentsize + 10;
//apply the new fontsize to all elements within another element (here body)
$('body').css('fontSize', currentsize+'%');
}
</script>
精彩评论