In jQuery, how to define a function with a selector as a parameter?
javascript, jquery
Solution
function resizePhoto(selector){
var photoWidth = $(selector).width();
var photoHeight = $(selector).height();
if (imgHeight > imgWidth){
$(selector).css('width','100');
}
}
...
resizePhoto('#photo_preview'); //Usage
Problem
I am trying to define a function that would to that: ``` var photoWidth = $('#photo_preview').width(); var photoHeight = $('#photo_preview').height(); if (imgHeight > imgWidth){ $('#photo_preview').css('width','100'); } ``` My goal is to create a function that would be like: ``` resizePhoto(theselector); ``` ... with the parameter "theselector" being $('#photo_preview') or any other selector. NOTE: I can't use classes for this one. What should I do?