Jump to content

Best way to keep this JS DRY


Samuz

Recommended Posts

How do I keep this type of code DRY..

 

var test = $(window).height();
    $('#selector').css('height', test);

$(window).resize(function() {
        $('#selector').css('height', test);
    });

 

It would of been a good idea to just set a static css height, but I want it to appear a certain way regardless of the amount of pixels a user has going down the vertical axis.

 

This is just an example, but on one of my projects i've found that i'm repeating myself a lot in scenarios such as the above.

 

Anyone got any good idea?

Link to comment
https://forums.phpfreaks.com/topic/264451-best-way-to-keep-this-js-dry/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.