Samuz Posted June 19, 2012 Share Posted June 19, 2012 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 More sharing options...
Jessica Posted June 19, 2012 Share Posted June 19, 2012 function windowResize(){ var test = $(window).height(); $('#selector').css('height', test); } $(window).resize('windowResize'); windowResize(); Link to comment https://forums.phpfreaks.com/topic/264451-best-way-to-keep-this-js-dry/#findComment-1355220 Share on other sites More sharing options...
Samuz Posted June 19, 2012 Author Share Posted June 19, 2012 function windowResize(){ var test = $(window).height(); $('#selector').css('height', test); } $(window).resize('windowResize'); windowResize(); Yeah.. Is it weird I completely forgot about JS functions? Thanks anyhow! Link to comment https://forums.phpfreaks.com/topic/264451-best-way-to-keep-this-js-dry/#findComment-1355222 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.