javascript - How to merge more than 2 DOM objects using jQuery? -


is possible merge 3 or more dom objects in jquery? found solution here in stackoverflow, merging 2 objects: merging jquery objects

my example:

var input1 = $('.input-1'),     input2 = $('#parent-div input'),     input3 = $('.input-3'),     input4 = $('.input-4'),     input5 = $('.input-5')      merge([input1, input2, input3, input4]).val('my custom input text'); 

in case have several inputs want merge few of them.

can use $.add() in following way:

$(document).ready(function(){    var input1 = $('.input-1');     var input2 = $('#parent-div input');     var input3 = $('.input-3');     var input4 = $('.input-4');     var input5 = $('.input-5');        var collection = $( input1 );    // capture new collection    collection = collection.add( input2).add(input3).add(input4);    collection.val('my custom input text');  });  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>  <input type="text" class="input-1" value="defualt text" >  <div id="parent-div">    <input type="text" class="input-2" value="defualt text" >    <input type="text" class="input-3" value="defualt text" >  </div>    <input type="text" class="input-3" value="defualt text" >  <input type="text" class="input-4" value="defualt text" >  <input type="text" class="input-5" value="defualt text" >


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -