javascript - Wrap function Jquery for multiple elements -


i've function in jquery

function row_content(col1, col2) {  		var divs = col1 + col2;    		for(var n = 0; n < divs.length; n+=2){  			divs.slice(n, n+2).wrapall('<div class="row-content"></div>');  		}  	}    	var col_2_3 = $('.col_2_3');  	var col_1_3 = $('.col_1_3');    	row_content(col_2_3, col_1_3);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>  <div class='col_2_3'>test</div>  <div class='col_1_3'>test</div>    <div class='col_2_3'>test</div>  <div class='col_1_3'>test</div>

i want, function wrap 2 divs in .row-content not work.

thanks !

the problem

var divs = col1 + col2; 

where col1,col2 jquery objects. above line concatenates inputs , does not combine selectors. length wont work wish to.

use jquery .add()

var divs = col1.add(col2); 

http://jsfiddle.net/7w6by7lz/


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -