1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| <!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta http-equiv="cache-control" content="public, max-age=60">
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0">
<meta name="author" content="Daniel Hagnoul">
<title>Test</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/sunny/jquery-ui.css">
<style>
hr { margin-top: 1.5rem; }
.edition { color: lightGrey; }
</style>
</head>
<body>
<h3 id="titre">Titre</h3>
<hr>
<div id="div1">Hello</div>
<hr>
<div class="boutons">
<button id="btn1">Btn 1</button>
<button id="btn2">Btn 2</button>
<button id="btn3">Btn 3</button>
</div>
<hr>
<button id="navBouton">Nav Bouton</button>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
"use strict";
$( function(){ // forme abrégée de $(document).ready( function( ){
let
jObjDiv1 = $( "#div1" ),
jObjTitre = $( "#titre" ),
jObjBtns = $( ".boutons, #navBouton" ),
relook = function( domArray ) {
$.each( domArray, function( i, item ) {
$( item )
.css( "background-color", "red" )
.addClass( "edition" );
});
};
/*
* $.merge() ! http://api.jquery.com/jQuery.merge/
* Merge the contents of two arrays together into the first array.
*/
relook( $.merge( jObjDiv1, jObjBtns ) );
// Mais il y a un os, jObjDiv1 a été transformé !
console.log( jObjDiv1 );
jObjDiv1.eq( 1 ).css( "background-color", "yellow" );
// Il faut partir d'un nouvel array
$.each( $.merge( [ ], $( "#btn2" ), $( "#navBouton" ) ), function( i, item ){
$( item ).css({
"padding" : "0.5rem",
"margin-left" : "1rem"
});
});
});
$( window ).load( function(){
});
</script>
</body>
</html> |
Partager