Extending jQuery, loop through all selected elements -


i'm trying make jquery function make elements same height.

i want call this

$('ul#items li').makesameheight(); 

that should make li's same height. need loop through li's , max height. how do that? eg.

(function ($) {   $.fn.makesameheight() = function (opts) {     // put here?   }; } (jquery)); 

edit :

if curious, here final function, psl

(function ($) {   $.fn.makesameheight = function (opts) {     var maxh = 0;     this.each(function () {       maxh = math.max(maxh, $(this).height());     });     this.each(function () {       $(this).height(maxh);     });     return this;   }; } (jquery)); 

is looking for:-

(function ($) {   $.fn.makesameheight = function (opts) {  //this inside jquery plugin function refers result of jquery selector            //itself jquery object. in case list of li's       this.each(function(){ //iterate through selected elements          alert($(this).css('height'));  //here $(this) particular element          //to set height $(this).css('height','yourheightvalue');       });     // put here?     return this;  //return elements chaining.   }; } (jquery));  $('ul#items li').makesameheight(); 

fiddle

example:-

(function ($) {   $.fn.makesameheight = function (opts) {       this.each(function(){      $(this).css('height', opts.height);       });     return this;   }; } (jquery));  $('ul#items li').makesameheight({'height':'30px'}); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -