开发者

jQuery - all elements on page to array

开发者 https://www.devze.com 2023-02-01 13:27 出处:网络
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.

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 ems) 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:

  1. 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>
0

精彩评论

暂无评论...
验证码 换一张
取 消